ts-sqlx
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

ts-sqlx

license npm (scoped)

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);

Readme

Keywords

Package Sidebar

Install

npm i ts-sqlx

Weekly Downloads

2

Version

0.1.1

License

(MIT OR Apache-2.0)

Unpacked Size

3.16 kB

Total Files

5

Last publish

Collaborators

  • nathanfaucett