Reputation: 323
I am trying to make a query in prisma that given a table received as parameter from an http request queries the first 100 rows from given table.
I am using the following query:
let rows = await prisma.$queryRawUnsafe\`SELECT * FROM ${collection} LIMIT 100\`;
However I receive the following error:
error - PrismaClientKnownRequestError:
Invalid `prisma.$queryRaw()` invocation:
Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error on "$1"`
Upvotes: 2
Views: 1199
Reputation: 7558
You would need to invoke the queryRawUnsafe method like this:
let collectionName = 'User'
let rows = await prisma.$queryRawUnsafe(`SELECT * FROM ${collectionName} LIMIT 100`)
Here's a reference to queryRawUnsafe method: Documentation
Upvotes: 1