ts-sqlx
v0.1.2
Published
Typescript SQLx compile-time checked queries without a DSL.
Downloads
15
Readme
ts-sqlx
Typescript SQLx compile-time checked queries without a DSL. see main package
import { sqlx, type SqlxString } from 'ts-sqlx';
import Pool from 'pg-pool';
const pool = new Pool();
function query<P extends unknown[], R = unknown>(
query: SqlxString<P, R>,
...params: P
): Promise<R[]> {
return pool.query(query, params).then((result) => result.rows);
}
const post = await query(sqlx('select p.* from posts p where p.id = $1;'), 1);
console.log(post);
See example for a "full" project example