1.0.4 • Published 7 years ago

pg-do v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

pg-do

Build Status Coverage Status npm Github Releases

API

Client

const PG = require('pg-do');
const client = new PG('postgres://test:123456@127.0.0.1:5432/test?max=20&idleTimeout=5000');
client.on('acquire', () => console.info('acquire'));
client.on('remove', () => console.info('remove'));
client.on('error', () => console.info('error'));
client.on('connect', () => console.info('connect'));

getTable

Get the table instance

const userSchema = {
  account: 'varchar(80) unique',
  createdAt: 'varchar(24) NOT NULL',
  email: 'varchar(160)',
  age: 'smallint CHECK (age > 0)',
};
client.addSchema('users', userSchema);
const users = client.getTable('users');

Table.insert

Insert the data to table

const user = await users.insert({
  account: 'vicanso',
  email: 'vicansocanbico@gmail.com',
  age: 30,
}, 'account createdAt');


const arr = await users.insert([
  {
    account: 'a',
  },
  {
    account: 'b',
  },
], 'account');

Table.count

Count the data

const count = await users.count({
  account: 'vicanso',
});

const total = await users.count({});

Table.findOne

Find one record

const user = await users.findOne({});

const user = await user.findOne({
  age: 20,
});

Table.find

Find records

const data = await users.find({});

LICENSE

ISC

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago