sqleye
v1.3.0
Published
A Fast in memory SQL abstraction (database)
Downloads
3
Maintainers
Readme
sqleye
Fast in memory database. Currenlty supports sqllite3
Overview
sqleye is a beautiful abstraction for sqllite3. Remember, Beauty lies in the eyes of the beholder. Anyone with an eye to use sqllite3 don't want to be bothered with the murky details behind.
sqleye is a fast and easy to use in memory database that uses sqllite3 in the background. This means developers don't need to write any DB code. Given the fact that database operations take time and are asynchronous. This module relieves users of those facts. Just use objects as you do in nodejs and they will automatically be synced to an sqllite3 database.
Currently works with sqllite3 only.
Features
Install
npm install sqleye
Require it in your code
var sqleye = require ('sqleye')
Creating objects.
To write a nodejs object to a database, Just call the constructor to outline the fields of the object. This is the schema.
// The first parameter lays out the object fields, Only text and int are currently supported for field types
// The second parameter is the primary key
// The third parameter specifies the database type, currently this is only 'sqllite'
// The fourth parameter is the name of your database.
var objStore = new sqleye ( { name: 'text', place: 'text', animal: 'text', pin: 'integer' },
[ 'name' ],
'sqllite',
'mydb' )
// Whenever you create an object with the above fields. just insert it.
var b = { name: 'James', place: 'Vancouver', animal: 'Tiger', pin: 1234 }
objStore.insert(b)
// To query
objStore.query ([ 'James' ])
Using multiple fields as the primary key
// To have both the name and pin to be unique and used as the primary key, it's easy
// In the constructor, just provide parameter 2 as [ 'name', 'pin' ].
var objStore = new sqleye ( { name: 'text', place: 'text', animal: 'text', pin: 'integer' },
[ 'name', 'pin' ],
'sqllite',
'mydb' )
// This time query by both name and pin
objStore.query ( ['James', 1234] )
Turning off Database support.
sqleye also supports a plain in-memory object store without writing to any Database. To use this support, just provide 'mem' as the third parameter to the sqleye constructor. This is good for programs that don't need persistency but a real fast cache in memory to work with.
// Providing 'mem' as the third parameter disables all DB operations.
var objStore = new sqleye ( { name: 'text', place: 'text', animal: 'text', pin: 'integer' },
[ 'name', 'pin' ],
'mem',
'mydb' )