darkTower
darkTower
PPrisma
Created by darkTower on 5/17/2024 in #help-and-questions
Should I stick with raw SQL?
My models look like this.
model Court {
court_id Int @id @default(autoincrement()) @db.UnsignedInt
courtName String @map("name") @db.VarChar(120)
court_num String? @map("number") @db.VarChar(10)
(...other court fields)
state_fee Decimal? @db.Decimal(5, 2)
court_fee Decimal? @db.Decimal(5, 2)
school_fee Decimal? @db.Decimal(5, 2)
citation Citation[]
@@map("court")
}

model Citation {
student_citation_id Int @id @default(autoincrement())
student_registration_id Int
(...other Citation fields)
court_id Int?
student_registration student_registration? @relation(fields: [student_registration_id], references: [student_registration_id])
court Court? @relation(fields: [court_id], references: [court_id])
@@map("student_citation")
}

model student_registration {
student_registration_id Int @id @default(autoincrement())
user_id Int @unique(map: "user_id")
(...student info fields)
enrollment enrollment[]
user user @relation(fields: [user_id], references: [user_id])
citation Citation[]
}

model user {
user_id Int @id @unique @default(autoincrement())
(... user fields)
student_registration student_registration?
}

model enrollment {
enrollment_id Int @id @default(autoincrement()) @db.UnsignedInt
student_registration_id Int @db.UnsignedInt
course_id Int @db.UnsignedInt
(... enrollment fields)
student_registration student_registration @relation(fields: [student_registration_id], references: [student_registration_id])
}
model Court {
court_id Int @id @default(autoincrement()) @db.UnsignedInt
courtName String @map("name") @db.VarChar(120)
court_num String? @map("number") @db.VarChar(10)
(...other court fields)
state_fee Decimal? @db.Decimal(5, 2)
court_fee Decimal? @db.Decimal(5, 2)
school_fee Decimal? @db.Decimal(5, 2)
citation Citation[]
@@map("court")
}

model Citation {
student_citation_id Int @id @default(autoincrement())
student_registration_id Int
(...other Citation fields)
court_id Int?
student_registration student_registration? @relation(fields: [student_registration_id], references: [student_registration_id])
court Court? @relation(fields: [court_id], references: [court_id])
@@map("student_citation")
}

model student_registration {
student_registration_id Int @id @default(autoincrement())
user_id Int @unique(map: "user_id")
(...student info fields)
enrollment enrollment[]
user user @relation(fields: [user_id], references: [user_id])
citation Citation[]
}

model user {
user_id Int @id @unique @default(autoincrement())
(... user fields)
student_registration student_registration?
}

model enrollment {
enrollment_id Int @id @default(autoincrement()) @db.UnsignedInt
student_registration_id Int @db.UnsignedInt
course_id Int @db.UnsignedInt
(... enrollment fields)
student_registration student_registration @relation(fields: [student_registration_id], references: [student_registration_id])
}
5 replies
PPrisma
Created by darkTower on 5/17/2024 in #help-and-questions
Should I stick with raw SQL?
It seems like my primary issuse now is no support to groupBy court.
5 replies
PPrisma
Created by darkTower on 5/17/2024 in #help-and-questions
Should I stick with raw SQL?
I think I've mostly solved this by doing
return this.prisma.enrollment.findMany({
include: {
student_registration: {
include: {
user: true,
citation: {
include: {
court: true,
},
},
},
},
},
where: {
completedDate: {
gte: `${startDate}`,
lt: `${endDate}`,
},
},
});
return this.prisma.enrollment.findMany({
include: {
student_registration: {
include: {
user: true,
citation: {
include: {
court: true,
},
},
},
},
},
where: {
completedDate: {
gte: `${startDate}`,
lt: `${endDate}`,
},
},
});
5 replies