kami gerami
08/02/2022, 2:48 PMkami gerami
08/02/2022, 3:11 PM// Timereport
model Timereport {
id String @id @default(cuid())
date String
event String
hours Float
user User? @relation(fields: [email], references: [email])
email String? @unique
locked Boolean @default(false)
project Project? @relation(fields: [projectName], references: [name])
projectName String?
@@unique([date, event]) // Do not allow multiple entries of same date + event
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
role Role @default(USER)
timereport Timereport[]
}kami gerami
08/02/2022, 3:13 PMNurul
08/03/2022, 12:38 PMimport { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient({
log: ['query'],
});
async function main() {
await prisma.user.create({
data: {
email: 'sundarani@prisma.io',
emailVerified: new Date(),
name: 'Sundarani',
timereport: {
create: {
date: '2020-01-01',
event: 'test',
hours: 1,
},
},
},
});
const reports = await prisma.timereport.findMany({
where: {
email: 'sundarani@prisma.io',
date: {
lt: '2022-01-01',
gt: '2019-01-01',
},
},
include: {
user: true,
},
});
console.log('reports', reports);
}
main()
.catch((e) => {
throw e;
})
.finally(async () => {
await prisma.$disconnect();
});
Here’s the output:
> ts-node index.ts
prisma:query SELECT "public"."Timereport"."id", "public"."Timereport"."date", "public"."Timereport"."event", "public"."Timereport"."hours", "public"."Timereport"."email", "public"."Timereport"."locked", "public"."Timereport"."projectName" FROM "public"."Timereport" WHERE ("public"."Timereport"."email" = $1 AND "public"."Timereport"."date" < $2 AND "public"."Timereport"."date" > $3) OFFSET $4
prisma:query SELECT "public"."User"."id", "public"."User"."name", "public"."User"."email", "public"."User"."emailVerified", "public"."User"."image" FROM "public"."User" WHERE "public"."User"."email" IN ($1) OFFSET $2
reports [
{
id: 'cl6dlbaoo0001cwlffzrkmwod',
date: '2020-01-01',
event: 'test',
hours: 1,
email: 'sundarani@prisma.io',
locked: false,
projectName: null,
user: {
id: 'cl6dlbaon0000cwlfgrv2zzja',
name: 'Sundarani',
email: 'sundarani@prisma.io',
emailVerified: 2022-08-03T12:33:19.219Z,
image: null
}
}
]kami gerami
08/03/2022, 12:46 PMkami gerami
08/03/2022, 12:47 PMkami gerami
08/03/2022, 12:47 PMkami gerami
08/03/2022, 12:48 PMkami gerami
08/03/2022, 12:48 PMkami gerami
08/03/2022, 12:48 PMNurul
08/03/2022, 12:50 PMkami gerami
08/03/2022, 1:43 PM