Reputation: 1581
I know I can run a raw sql with:
import { sql } from 'kysely'
const id = 123
const snippet = sql<Person[]>`select * from person where id = ${id}`
but I want to make a function that will accept different WHERE clauses and params, something like:
function runQuery(sql: string, args: any): Person[] {
... // how to?
}
and then invoke it with different sql+args values:
runQuery('SELECT * from person WHERE id = ${id}', { id: 123})
runQuery('SELECT * from person WHERE name = ${id}', { name: 'John'})
... and be protected from the SQL injection etc.
Is this possible with Kysely?
Upvotes: 0
Views: 377
Reputation: 551
finally I found the solution to call some stored proc from Kysely:
let rep = await sql<SpValideLoginUsagerRep>`
declare @retour int
exec @retour = [dbo].[ValideLoginUsager] ${params.codeUsager}, ${params.passphrase}, ${params.password}
select @retour as [valide]
`.execute(ewGlobal);
Upvotes: 0