SQL template

This guide assumes familiarity with:

SQL template is the core of Waddler.

import { waddler } from "waddler";

const sql = waddler({ dbUrl: ":memory:" });

await sql`select 1`;

It’s based on tagged templates. This enables powerful, safe, yet simple SQL API in JavaScript and TypeScript:

await sql`select * from users where id = ${10}`; 
// ^ gets parametrised, protects from SQL injections
select * from users where id = $1;
-- 10 will be provided in params [10]

SQL template is packed with convenient goodies:

sql.identifierconveniently pass identifiers to SQL query with automatic escaping
sql.valuesconveniently pass values to insert statements
sql.rawdynamically build SQL by embedding raw strings
sql.defaultSQL DEFAULT values for queries
toSQLprepares and converts sql query to { query: string, params: any[] }
streamstreams result row by row
chunkedstreams result in chunks