mydown
v1.2.0
Published
MySQL backend for LevelUP.
Downloads
15
Readme
MyDOWN
MySQL as a LevelUP backend with multi table support. Inspired from SQLdown, MyDOWN leverages node-mysql with simplified queries for better performance.
npm install mydown
mydown = require('mydown')(database, [config])
MyDOWN factory. Supply MySQL connection options and pool options as config
.
//MyDOWN factory
var mydown = require('mydown')('db', {
connectionLimit: 10,
host: 'localhost',
user: 'bob',
password: 'secret'
})
Database needs to be created before initializing MyDOWN:
mysql -uroot -p -e "CREATE DATABASE IF NOT EXISTS db"
levelup(table, { db: mydown })
MyDOWN consumed by LevelUP, where location
argument defines the table.
options.prefix
MyDOWN batch()
is a transactional operation that can be applied into multiple tables, by setting the options.prefix
property.
//tables a, b, c
var a = levelup('a', { db: mydown })
var b = levelup('b', { db: mydown })
var c = levelup('c', { db: mydown })
a.batch([
{ type: 'put', key: 'foo', value: 'a' },
{ type: 'put', key: 'foo', value: 'b', prefix: b }, //levelup prefix
{ type: 'put', key: 'foo', value: 'c', prefix: 'c' } //string prefix
], function () {
a.get('foo', function (err, val) {
//val === 'a'
})
b.get('foo', function (err, val) {
//val === 'b'
})
c.get('foo', function (err, val) {
//val === 'c'
})
})
Tests
Abstract-LevelDOWN test suite is green except for 'implicit iterator snapshot'. This is because 'implicit snapshot' is not the default behavior of a transactional database. Implementing this would require more complicated query and schema, thus bad performance for very little gain in real-world use cases.
License
MIT