Kieran Salawu
07/15/2021, 10:45 AMRyan
07/15/2021, 10:49 AMKieran Salawu
07/15/2021, 10:49 AMKieran Salawu
07/15/2021, 10:49 AMKieran Salawu
07/15/2021, 10:50 AMfindMany
to get a list of users from my db, i use some customSQL to get the data from that table i need, but i want the results to be in the same for as if it where using findManyRyan
07/15/2021, 10:56 AMmap
function that does just this conversion should work. And then you can use that in your logic to return in the same way.Ryan
07/15/2021, 10:56 AMKieran Salawu
07/15/2021, 11:01 AMRyan
07/15/2021, 11:03 AMimport { Prisma } from '@prisma/client'
const map = (data): Prisma.UserGetPayload => {
// return the data as per the return type
}
Kieran Salawu
07/15/2021, 11:10 AMKieran Salawu
07/15/2021, 11:10 AMRyan
07/15/2021, 11:11 AMKieran Salawu
07/15/2021, 11:15 AMKieran Salawu
07/15/2021, 11:15 AMmodel User {
id Int @id @default(autoincrement()) @map("user_id")
email String @unique @map("user_email")
posts Post[]
}
model Post {
id Int @id @default(autoincrement()) @map("post_id")
title String @db.VarChar(255) @map("post_title")
author User? @relation(fields: [authorId], references: [id])
authorId Int? @map("post_author_id")
}
Kieran Salawu
07/15/2021, 11:15 AMKieran Salawu
07/15/2021, 11:17 AMconst users = await prisma.user.findMany()
Kieran Salawu
07/15/2021, 11:17 AMKieran Salawu
07/15/2021, 11:18 AMctx.prisma.users
.findUnique({
where: { id: 1 },
})
.posts()
Kieran Salawu
07/15/2021, 11:19 AMKieran Salawu
07/15/2021, 11:19 AMKieran Salawu
07/15/2021, 11:21 AMconst myUser = ctx.prisma.$queryRaw(
`SELECT * from customSearch(${userId})`,
)
const myUserPrisma = someConvertFunction(myUser)
const posts = myUserPrisma.posts()