Bamada
09/23/2021, 10:12 PMPrisma 3.1.1
with one of my projects.
Inside my code, I use the rawQuery
below and I want to type the result of the query.
const configs = await this.prismaService.$queryRaw<Config[] >`SELECT id, employee_id, start_date, end_date
FROM configs mc
WHERE employee_id IN (${Prisma.join(employeeIds)})
AND DATE_PART('year', mc.start_date) = CAST(${year} AS INTEGER)
AND CAST(${month} AS INTEGER) >= DATE_PART('month', mc.start_date)
AND CAST(${month} AS INTEGER) <= DATE_PART('month', COALESCE(end_date,'2020-12-01'))`;
// generated type
export type Config = {
id: number
employeeId: string
startDate: Date
endDate: Date | null
}
// Expected result
[Config{id:1, startDate:xxxx, endDate:xx, ..}, ..]
// I got
[{id:1, start_date:xxxx, end_date:xx, ..}, ..]
Do you know what’s wrong with my query?
I looked at the documentation https://www.prisma.io/docs/concepts/components/prisma-client/raw-database-access and I didn’t found my mistake
thksGaml
09/24/2021, 8:02 AMConfig(id: 1, ...)
, do you mean you expect a class instance?
To my undesrstanding, all prisma types are interfaces, not classes and what you get back seems to match the generated type.Bamada
09/24/2021, 8:24 AMGaml
09/24/2021, 8:26 AMBamada
09/24/2021, 8:32 AMRyan
09/27/2021, 6:42 AMBamada
09/27/2021, 7:30 AMmodel MercureConfig {
id Int @id @default(autoincrement())
po Int @unique
poLineNumber Int @map("po_line_number")
employeeId String @map("employee_id")
totalDays Int @map("total_days")
startDate DateTime @map("start_date")
endDate DateTime? @map("end_date")
@@map("mercure_configs")
}
If I understand well if I use @map
inside a schema and a $rawquery
I need to manually define a type right?Ryan
09/27/2021, 7:52 AMBamada
09/27/2021, 8:59 AM