Waddler SQL unsafe
This guide assumes familiarity with:
sql.unsafe lets you use a client itself by providing sql string and params
const response = await sql.unsafe('select * from users where id = @p1', [10]);select * from users where id = @p1;
-- params: [10]MsSql accepts parameter placeholders in the format: @<parameter name>
During parameterization Waddler generates placeholders in the following way: @p<parameter number>, where the parameter number starts from 1.
These parameters are then bound to the query by their names.
If you want to write a query with placeholders in your own format, you should provide a custom getParamName function in the options of the sql.unsafe function.
const response = await sql.unsafe(
'select * from users where id = @par1',
[10],
{ getParamName: (paramNumber: number) => `par${paramNumber}`, }
);select * from users where id = @par1;
-- params: [10]