Reputation: 43
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
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