0.1.2 • Published 6 years ago

rxpg v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

RxPg

Build Status

Installation

$ npm i rxpg

Getting started

import { RxPg } from 'rxpg';

There are three possible approaches for RxPg initialization:

With env variables:

PGHOST='localhost'
PGUSER='root'
PGDATABASE='postgres'
PGPASSWORD='root'
PGPORT=5432
const rxpg = new RxPg();

With connection url

const rxpg = new RxPg('postgres://user:password@host:port/database');

With config object

const rxpg = new RxPg({
  host: 'localhost',
  user: 'root',
  password: 'root',
  database: 'postgres',
  max: 50,
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000
});

Query example

rxpg.query(
  'INSERT INTO users(name, email) VALUES($1, $2) RETURNING *',
  ['brianc', 'brian.m.carlson@gmail.com']
).subscribe(console.log)

Transaction example

rxpg.transaction(
  (rxpg, previousQueryResult) => rxpg.query('INSERT INTO users(name) VALUES($1) RETURNING id', ['brianc']),
  (rxpg, previousQueryResult) => rxpg.query('INSERT INTO photos(user_id, photo_url) VALUES ($1, $2)', previousQueryResult[0].id, 's3.bucket.foo'),
).subscribe(console.log);
0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago