PostgreSQL driver for SqlTags (@sqltags/core) 🔧✨ Safely create & execute parameterized SQL queries using template strings
npm install @sqltags/pg!Build status

This is the PostgreSQL driver for the @sqltags/core library.
Please refer to the @sqltags/core project README for
more information.
🔧✨ Safely create & execute parameterized SQL queries using template strings.
``tsSELECT * FROM users WHERE id = ${userId}
const [user] = await sql;`
Results in the following query:
`sql`
SELECT * FROM users WHERE id = $1
-- with parameters: [123]
Install:
`sh`
npm install @sqltags/core @sqltags/pg
Create & connect a PostgreSQL Client or Pool instance, then create a SQL tag using the connection:
`ts
import { Client } from 'pg';
import { createPgTag } from '@sqltags/pg';
const client = new Client({
/ ... /
});
await client.connect();
const sql = createPgTag(client);
`
`ts
import { Pool } from 'pg';
import { createPgTag } from '@sqltags/pg';
const pool = new Pool({
/ ... /
});
const sql = createPgTag(pool);
`
Query:
`tsSELECT * FROM users WHERE id = ${userId}
const [user] = await sql;`
Don't forget to disconnect your client when finished!
`ts``
await client.end();