block-sequence-mysql

1.0.0 • Public • Published

block-sequence-mysql

A MySQL 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-mysql')
 
// Initialise the MySql Block Sequence Driver
init({ host: '127.0.0.1', database: 'bs_test', user: 'root' }, (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 https://www.npmjs.com/package/mysql for all connection parameters

Package Sidebar

Install

npm i block-sequence-mysql

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • guidesmiths_bot
  • feliun
  • ulisesgascon
  • cressie176