josh taylor
josh taylor
PPrisma
Created by josh taylor on 9/12/2024 in #help-and-questions
Adding arguments to rawQueryTyped with MySql
The docs mention that you can add arguments to rawQueryTyped queries https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/typedsql#passing-arguments-to-typedsql-queries
SELECT id, name, age
FROM users
WHERE age > ? AND age < ?
SELECT id, name, age
FROM users
WHERE age > ? AND age < ?
I'm pretty inexperienced with raw sql, so I have a few questions: 1. The docs show the example of getUsersByAge(minAge, maxAge). How exactly are the variables minAge, maxAge mapped to the positional placeholders? is it based on the order that the placeholders appear? 2. What if I want to use a parameter multiple times? Will I have to pass in the parameter multiple times? 3. Is there a way to pass in the parameter, set it to a variable name in the SQL script, and reuse the variable name?
1 replies