asdf
asdf

Reputation: 43

getting the latest data from prisma client by id

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model Data {
  id        Int     @id @default(autoincrement())
  longitude Float
  latitude  Float
  distance  Int
}

How can I get the latest data by id?
I am using @prisma/client and postgresql.

Upvotes: 1

Views: 2440

Answers (1)

Danila
Danila

Reputation: 18486

Basically you just want to order data by id in descending order?

Here we go:

import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

const data = await prisma.data.findMany({ orderBy: { id: 'desc' } });

Upvotes: 5

Related Questions