block-sequence-postgres
Advanced tools
Comparing version 0.1.1 to 1.0.0
@@ -8,5 +8,8 @@ var debug = require('debug')('block-sequence:postgres') | ||
var path = require('path') | ||
var bigInt = require('big-integer') | ||
module.exports = function init(config, cb) { | ||
if (typeof Promise === 'undefined') global.Promise = require('promise-polyfill') | ||
if (Number.MAX_SAFE_INTEGER === undefined) Number.MAX_SAFE_INTEGER = 9007199254740991 | ||
if (arguments.length === 1) return init({}, arguments[0]) | ||
@@ -80,3 +83,5 @@ if (!config.url) return cb(new Error('url is required')) | ||
// Because value is a BIGINT which could execeed Number.MAX_SAFE_INTEGER postgres returns a string. | ||
cb(err, { name: record.name, value: parseInt(record.value, 10), metadata: metadata }) | ||
var value = bigInt(record.value) | ||
if (value.greater(Number.MAX_SAFE_INTEGER)) return cb(new Error('Sequence value exceeds Number.MAX_SAFE_INTEGER')) | ||
cb(err, { name: record.name, value: value.toJSNumber(), metadata: metadata }) | ||
}) | ||
@@ -83,0 +88,0 @@ } |
{ | ||
"name": "block-sequence-postgres", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "A Postgres implementation of block-sequence", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node tests/compliance.tests.js | tap-spec", | ||
"test": "node test/compliance.tests.js | tap-spec", | ||
"lint": "eslint .", | ||
"istanbul": "istanbul cover --report html --report lcov tape -- test/compliance.tests.js", | ||
"codeclimate": "codeclimate-test-reporter < coverage/lcov.info", | ||
"prepush": "npm run lint && npm test", | ||
"docker": "docker run --detach --publish 5432:5432 --name bs-postgres postgres" | ||
"docker": "docker run --detach --publish 5432:5432 --name postgres kiasaki/alpine-postgres" | ||
}, | ||
@@ -23,14 +25,18 @@ "keywords": [ | ||
"devDependencies": { | ||
"block-sequence-compliance-tests": "0.1.0", | ||
"eslint": "^0.24.1", | ||
"eslint-config-imperative": "0.0.6", | ||
"eslint-plugin-imperative": "0.0.2", | ||
"husky": "^0.11.4", | ||
"block-sequence-compliance-tests": "^2.0.1", | ||
"codeclimate-test-reporter": "^0.4.0", | ||
"eslint": "^3.12.2", | ||
"eslint-config-imperative": "^1.0.0", | ||
"eslint-plugin-imperative": "^1.0.0", | ||
"husky": "^0.13.0", | ||
"istanbul": "^0.4.5", | ||
"tap-spec": "^4.1.1" | ||
}, | ||
"dependencies": { | ||
"async": "^2.0.0-rc.3", | ||
"debug": "^2.2.0", | ||
"lodash": "^4.11.1", | ||
"pg": "^4.5.5", | ||
"async": "^2.1.4", | ||
"big-integer": "^1.6.17", | ||
"debug": "^2.6.0", | ||
"lodash": "^4.17.4", | ||
"pg": "^6.1.2", | ||
"promise-polyfill": "^6.0.2", | ||
"safe-json-parse": "^4.0.0" | ||
@@ -48,3 +54,3 @@ }, | ||
}, | ||
"homepage": "https://github.com/guidesmiths/block-sequence-postgres#readme" | ||
"homepage": "https://guidesmiths.github.io/block-sequence-postgres/" | ||
} |
# block-sequence-postgres | ||
A PostgreSQL implementation of [block-sequence](https://www.npmjs.com/package/block-sequence). | ||
[![NPM version](https://img.shields.io/npm/v/block-sequence-postgres.svg?style=flat-square)](https://www.npmjs.com/package/block-sequence-postgres) | ||
[![NPM downloads](https://img.shields.io/npm/dm/block-sequence-postgres.svg?style=flat-square)](https://www.npmjs.com/package/block-sequence-postgres) | ||
[![Build Status](https://img.shields.io/travis/guidesmiths/block-sequence-postgres/master.svg)](https://travis-ci.org/guidesmiths/block-sequence-postgres) | ||
[![Code Climate](https://codeclimate.com/github/guidesmiths/block-sequence-postgres/badges/gpa.svg)](https://codeclimate.com/github/guidesmiths/block-sequence-postgres) | ||
[![Test Coverage](https://codeclimate.com/github/guidesmiths/block-sequence-postgres/badges/coverage.svg)](https://codeclimate.com/github/guidesmiths/block-sequence-postgres/coverage) | ||
[![Code Style](https://img.shields.io/badge/code%20style-imperative-brightgreen.svg)](https://github.com/guidesmiths/eslint-config-imperative) | ||
[![Dependency Status](https://david-dm.org/guidesmiths/block-sequence-postgres.svg)](https://david-dm.org/guidesmiths/block-sequence-postgres) | ||
[![devDependencies Status](https://david-dm.org/guidesmiths/block-sequence-postgres/dev-status.svg)](https://david-dm.org/guidesmiths/block-sequence-postgres?type=dev) | ||
## Usage | ||
```js | ||
var BlockArray = require('block-sequence').BlockArray | ||
var init = require('block-sequence-postgres') | ||
const BlockArray = require('block-sequence').BlockArray | ||
const init = require('block-sequence-postgres') | ||
// Initialise the PostgreSQL Block Sequence Driver | ||
init({ url: 'postgres://username:password@localhost/bs_test' }, function(err, driver) { | ||
init({ url: 'postgres://username:password@localhost/bs_test' }, (err, driver) => { | ||
if (err) throw err | ||
// Ensure the sequence exists | ||
driver.ensure({ name: 'my-sequence' }, function(err, sequence) { | ||
driver.ensure({ name: 'my-sequence' }, (err, sequence) => { | ||
if (err) throw err | ||
// Create a block array containing 1000 ids per block (defaults to 2 blocks) | ||
var idGenerator = new BlockArray({ block: { driver: driver, size: 1000 } }) | ||
const idGenerator = new BlockArray({ block: { sequence: sequence, driver: driver, size: 1000 } }) | ||
// Grab the next id | ||
idGenerator.next(function(err, id) { | ||
idGenerator.next((err, id) => { | ||
if (err) throw err | ||
@@ -28,5 +37,4 @@ console.log(id) | ||
``` | ||
See https://www.npmjs.com/package/pg for all connection parameters | ||
See [pg](https://www.npmjs.com/package/pg) for all connection parameters | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
10029
16
119
0
40
7
8
+ Addedbig-integer@^1.6.17
+ Addedpromise-polyfill@^6.0.2
+ Addedbig-integer@1.6.52(transitive)
+ Addedgeneric-pool@2.4.3(transitive)
+ Addedobject-assign@4.1.0(transitive)
+ Addedpacket-reader@0.3.1(transitive)
+ Addedpg@6.4.2(transitive)
+ Addedpg-pool@1.8.0(transitive)
+ Addedpgpass@1.0.5(transitive)
+ Addedpromise-polyfill@6.1.0(transitive)
+ Addedsemver@4.3.2(transitive)
+ Addedsplit2@4.2.0(transitive)
- Removedgeneric-pool@2.4.2(transitive)
- Removedpacket-reader@0.2.0(transitive)
- Removedpg@4.5.7(transitive)
- Removedpgpass@0.0.3(transitive)
- Removedsemver@4.3.6(transitive)
- Removedsplit@0.3.3(transitive)
- Removedthrough@2.3.8(transitive)
Updatedasync@^2.1.4
Updateddebug@^2.6.0
Updatedlodash@^4.17.4
Updatedpg@^6.1.2