Installations
npm install glider
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=0.12
Node Version
4.3.2
NPM Version
2.14.12
Score
55.5
Supply Chain
95.7
Quality
73.8
Maintenance
50
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (93.58%)
Shell (6.42%)
Developer
Innovu
Download Statistics
Total Downloads
4,220
Last Day
3
Last Week
9
Last Month
16
Last Year
270
GitHub Statistics
44 Commits
4 Watching
2 Branches
1 Contributors
Bundle Size
65.27 kB
Minified
19.48 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.1.0
Package Id
glider@0.1.0
Size
5.65 kB
NPM Version
2.14.12
Node Version
4.3.2
Total Downloads
Cumulative downloads
Total Downloads
4,220
Last day
0%
3
Compared to previous day
Last week
200%
9
Compared to previous week
Last month
-33.3%
16
Compared to previous month
Last year
-74.5%
270
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
glider
Simple, expressive, Promise-based API for interacting with Postgres built on node-postgres. Supports node.js 0.12+.
Table of Contents
Install
npm install --save glider
Usage
create a Database object
The Database
object is the core for most of the API. All you need to do is provide a connection string or client configuration object, just like in node-postgres with pg.connect.
1var db = glider('postgresql://postgres@localhost:5432/postgres'); 2 3// or... 4 5var db = glider({ 6 user: 'user', 7 password: 'password', 8 database: 'postgres', 9 host: 'localhost' 10});
basic queries
The mechanics of the basic query is identical to node-postgres, except that instead of providing a callback, glider
returns a Promise.
1var db = glider(CONNECTION_STRING); 2 3// "result" is a node-postgres result object 4db.query('select $1::integer as number', [1]).then(function(result) { 5 return result.command === 'SELECT' && result.rows[0].number === 1; // true 6});
getting data from queries (SELECT)
The following functions allow you to grab rows, a single row, or even a single value.
1var db = glider(CONNECTION_STRING); 2 3// array of rows 4db.select('select 1::integer as number').then(function(rows) { 5 return rows[0].number === 1; // true 6}); 7 8// single row 9db.one('select 1::integer as number').then(function(row) { 10 return row.number === 1; // true 11}); 12 13// single value 14db.value('select 1::integer as number').then(function(value) { 15 return value === 1; // true 16});
row count queries (INSERT/UPDATE/DELETE)
In the instance where you are doing non-returning queries that have a row count, like insert/update/delete, glider
has functions that will instead return the row count. This is a matter of convenience. If you need the full result object, use db.query()
.
The functions are functionally identical to each other, but allow the actual operation to be more expressive, which becomes extremely useful once you start using glider
's transactions.
1var db = glider(CONNECTION_STRING); 2 3db.query('insert into foo values (1, 2, 3), (3, 4, 5)').then(function(result) { 4 return result.rowCount === 2 && result.command === 'INSERT'; // true 5}); 6 7db.insert('insert into foo values (1, 2, 3), (3, 4, 5)').then(function(count) { 8 return count === 2; // true 9}); 10 11db.update('update foo set value = 1 where id = 1').then(function(count) { 12 return count === 1; // true 13}); 14 15db.delete('delete from foo where id = 2').then(function(count) { 16 return count === 1; // true 17});
postgres commands
You can also execute postgres commands or any query you don't need a result for with command()
. So whether you're invoking a CREATE
or ALTER
or just calling an insert/update/delete for which you don't need a result, use command()
.
1var db = glider(CONNECTION_STRING); 2 3db.command('create table foo (id serial, value integer)').then(function(result) { 4 return !result; // true 5}); 6 7db.command('insert into foo (value) values (1), (2)').then(function(result) { 8 return !result; // true 9});
transactions
glider
has a unique chaining API that allows you to string together a series of queries in a very clear, expressive manner. All connection pooling, result gathering, error handling, etc... is handled internally and a Promise is returned.
If there's an error in any of the queries in a transaction, glider
will automatically invoke a ROLLBACK
and reject the current Promise with the database error.
1var db = glider(CONNECTION_STRING); 2db 3 .begin() 4 .command('create table foo (id serial, value integer)') 5 .insert('insert into foo (value) values ($1), ($2), ($3)', [1, 2, 3]) 6 .update('update foo set value = 99 where id = 1') 7 .delete('delete from foo where id = 3') 8 .select('select * from foo') 9 .one('select value from foo where id = 1') 10 .value('select value from foo where id = 1') 11 .commit() 12 .then(function(results) { 13 console.log(results[0]); // undefined 14 console.log(results[1]); // 3 15 console.log(results[2]); // 1 16 console.log(results[3]); // 1 17 console.log(results[4]); // [ { id: 1, value: 99 }, { id: 2, value: 2 } ] 18 console.log(results[5]); // { id: 1, value: 99 } 19 console.log(results[6]); // 99 20 });
or a similar example of returning node-postgres
's result objects...
1var db = glider(CONNECTION_STRING); 2db 3 .begin() 4 .query('create table foo (id serial, value integer)') 5 .query('insert into foo (value) values (1), (2), (3)') 6 .query('update foo set value = 99 where id = 1') 7 .query('delete from foo where id = 3') 8 .query('select * from foo') 9 .commit() 10 .then(function(results) { 11 console.log(results[0].command); // CREATE 12 console.log(results[1].rowCount); // 3 13 console.log(results[2].rowCount); // 1 14 console.log(results[3].rowCount); // 1 15 console.log(results[4].rows); // [ { id: 1, value: 99 }, { id: 2, value: 2 } ] 16 });
and since the session is handled internally by glider
, you can make use of postgres's sequence manipulation functions, like in this trivial example...
1var db = glider(CONNECTION_STRING); 2db 3 .begin() 4 .query('create table foo (id serial, value integer)') 5 .insert('insert into foo (value) values (999)') 6 .one('select value from foo where id = lastval()') 7 .commit() 8 .then(function(value) { 9 console.log(value); // 999 10 });
Testing
To test, install the prerequisites, run npm test
, and vagrant will take care of spinning up a headless VM with a local postgres instance. All tests will be run against this instance. The vagrant VM will continue running after the tests complete to make subsequent test runs instant. You can shut down the VM at any time by running vagrant halt
, or remove the VM entirely with vagrant destroy
.
Prerequisites
Run tests (mocha + should)
npm test
Generate coverage report (istanbul)
Reports are generated in the ./coverage
folder. An HTML-based report can be loaded into the browser from ./coverage/lcov-report/index.html
.
npm run cover
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More