Gathering detailed insights and metrics for glider
Gathering detailed insights and metrics for glider
npm install glider
Typescript
Module System
Min. Node Version
Node Version
NPM Version
55.3
Supply Chain
95.7
Quality
73.8
Maintenance
50
Vulnerability
99.6
License
JavaScript (93.58%)
Shell (6.42%)
Total Downloads
4,216
Last Day
1
Last Week
7
Last Month
13
Last Year
269
44 Commits
4 Watching
2 Branches
1 Contributors
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
133.3%
7
Compared to previous week
Last month
-76.4%
13
Compared to previous month
Last year
-77.1%
269
Compared to previous year
1
Simple, expressive, Promise-based API for interacting with Postgres built on node-postgres. Supports node.js 0.12+.
npm install --save glider
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});
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});
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});
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});
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});
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 });
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
.
npm test
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
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-01-20
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