simple-pg
v1.0.0
Published
A simplified api against Postgresql using promises and objects Edit
Downloads
10
Readme
simple-pg
A simplified api against Postgresql using promises and objects
Install
npm install --save simple-pg
Use
select
pgm.select('users') // DON'T
pgm.select('users', {
columns: {},
where: {user_id: {ge: 1}, taxonomy_handle: '16', section: 'experience', taxonomy_type: 'profession'},
limit: 100
})
insert
pgm
.insert('users', user) // id assumed to be .id
.then(res => console.log(res)) // logs {id: INSERTED_ID}
pgm
.insert('users', 'user_id', user) // id is .user_id
.then(res => console.log(res)) // logs {user_id: INSERTED_ID}
upsert
pgm
.upsert('users', user) // id assumed to be .id
.then(res => console.log(res)) // logs user
pgm
.upsert('users', 'user_id', user) // id is .user_id
.then(res => console.log(res)) // logs user
update
pgm
.update('users', user) // where id = user.id
.then(res => console.log(res)) // logs array of {id: UPDATED_ID}
pgm
.update('users', 'user_id', user) // where user_id = user.user_id
.then(res => console.log(res)) // logs array of {user_id: UPDATED_ID}
pgm
.update('users', user, {user_id: 1, taxonomy_handle: '16', section: 'experience'})
// where user_id = 1 AND taxonomy_handle = '16' AND section = 'experience'
.then(res => console.log(res)) // logs array of {id: UPDATED_ID}
pgm
.update('users', 'user_id, user, {user_id: 1, taxonomy_handle: '16', section: 'experience'})
// where user_id = 1 AND taxonomy_handle = '16' AND section = 'experience'
.then(res => console.log(res)) // logs array of {user_id: UPDATED_ID}
delete
pgm
.del('users') // deletes all rows from the table 'users'
pgm
.del('users', undefined)
.catch(err => console.error(err))// logs 'Missing WHERE clause'
pgm
.del('users', {user_id: 1, taxonomy_handle: '16', section: 'experience'})
// where user_id = 1 AND taxonomy_handle = '16' AND section = 'experience'
truncate
pgm.truncate('users')