node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org »

pg-ts

pg-ts

Typescript wrapper around node-postgres

Installing

yarn add pg-ts

Using

Using promises:

import getPool, { SQL } from "pg-ts";
 
const pool = getPool();
const { firstName, lastName } = person;
 
pool.transaction(tx =>
  Promise
    .all([
      tx.none(SQL`INSERT INTO people (first_name, last_name) VALUES (${firstName}${lastName}))`),
      tx.one(SQL`SELECT * FROM people WHERE first_name = ${firstName})`),
    ])
    .then(([,person]) => person));

Using fp-ts BTasks:

import getPool, { SQL } from "pg-ts";
 
const pool = getPool();
 
pool.oneTask(SQL`SELECT * FROM people WHERE first_name = ${firstName})`).run();