JSPM

block-sequence-postgres

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q18033F
  • License ISC

A Postgres implementation of block-sequence

Package Exports

  • block-sequence-postgres

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (block-sequence-postgres) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

block-sequence-postgres

A PostgreSQL implementation of block-sequence.

NPM version NPM downloads Build Status Code Climate Test Coverage Code Style Dependency Status devDependencies Status

Usage

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' }, (err, driver) => {
    if (err) throw err

    // Ensure the sequence exists
    driver.ensure({ name: 'my-sequence' }, (err, sequence) => {
        if (err) throw err

        // Create a block array containing 1000 ids per block (defaults to 2 blocks)
        const idGenerator = new BlockArray({ block: { sequence: sequence, driver: driver, size: 1000 } })

        // Grab the next id
        idGenerator.next((err, id) => {
            if (err) throw err
            console.log(id)
        })
    })
})

See pg for all connection parameters