#Prisma seems to interact differently with a query that has been modified versus original
7 messages · Page 1 of 1 (latest)
export async function test(){
try {
let query = {
where : {
card_class: {
equals: c_class.Swordcraft
},
}
}
query.where = await add_entry_to_query(query.where, {
cost: {
equals: 7
},
})
// query = {
// where : {
// card_class: {
// equals: c_class.Swordcraft
// },
// cost: {
// equals: 7
// },
// }
// }
console.log(query)
//@ts-ignore
return await db.card.findMany(query)
}
catch(err){
throw new Error(`error: ${err}`)
}
}``` is the function i'm using to test this
async function add_entry_to_query(query_where : any, new_param : any) {
let query_keys = Object.keys(query_where)
let new_keys = Object.keys(new_param)
new_keys.forEach(key => {
if(query_keys.includes(key)){
query_where[key] = {...query_where[key], ...new_param[key]}
}
else{
Object.defineProperty(query_where, key, {
value: new_param[key]
})
}
})
return query_where
}```
is the add entry to query function i'm using
i'm not sure if prisma natively has something like this
outputs from the console.log and prisma query of both are as follows:
# using the add_entry method
{
where: {
card_class: {
equals: "Swordcraft",
},
cost: {
equals: 7,
},
},
}
prisma:info Starting a postgresql pool with 17 connections.
prisma:query SELECT (# a bunch of tables here #) FROM "public"."card" WHERE "public"."card"."card_class" = CAST($1::text AS "public"."c_class") OFFSET $2
versus
# using the hard assigned value
{
where: {
card_class: {
equals: "Swordcraft",
},
cost: {
equals: 7,
},
},
}
prisma:info Starting a postgresql pool with 17 connections.
prisma:query SELECT (# a bunch of tables here #) FROM "public"."card" WHERE ("public"."card"."card_class" = CAST($1::text AS "public"."c_class") AND "public"."card"."cost" = $2) OFFSET $3```