estk-pg

0.0.8 • Public • Published

estk-events-pg

Simple postgresql client used by other estk modules.

PostgresClient(databaseUrl)

Create a client by passing a valid postgres url

query(sql, params)

returns an array of objects, one per row

transaction()

starts a transaction and returns a wrapper

PostgresTransaction

query(sql, params)

run a query in the transaction scope

commit()

commit the transaction

rollback()

rollback the transaction

usage:

  const { PostgresClient } = require('estk-pg');
  const client = PostgresClient('postgres://localhost/db-name');
  const [result] = await client.query('select 42 as answer');
  console.log(result); // => { answer: 42 }

  const transaction = await client.transaction();
  await transaction.query('create table people(name text)');
  await transaction.query(`insert into people(name) values('Arthur')`);
  const rows = await transaction.query(`select * from people`);
  console.log(rows); // => [ { name: "Arthur" } ];
  await transaction.rollback()

Readme

Keywords

none

Package Sidebar

Install

npm i estk-pg

Weekly Downloads

1

Version

0.0.8

License

MIT

Unpacked Size

10.4 kB

Total Files

12

Last publish

Collaborators

  • davidmfoley