gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
How to pass variable in to a $queryRaw in Prisma
- User
How to pass variable in to a $queryRaw in Prisma
- Assistant
In Prisma, you can pass variables into a
$queryRawmethod by using the template literals syntax. Here's an example:const prisma = require('./your-prisma-client'); // Import your Prisma client const variable = 123; // Your variable value // Define your query with the variable placeholder const query = ` SELECT * FROM your_table WHERE your_column = ${variable} `; // Execute the query using $queryRaw and the defined query const result = await prisma.$queryRaw(query); console.log(result);Here, you define your query as a string using template literals and include the variable placeholder
${variable}where you want to pass in your value. Then, you use the$queryRawmethod on your Prisma client and pass in the query as an argument to execute it.Make sure to replace
your_tableandyour_columnwith the appropriate table and column names in your database.