Lowkie
Description
Lowkie is a lokijs object modeling tool designed to work in an asynchronous environment.
Installation
$ npm i lowkie
Usage (basic)
const lowkie = require('lowkie');
lowkie.connect(path.join(__dirname, './sampledb.json'),options)
.then((db) => {
console.log('connected db');
})
.catch(e => {
console.log('connection error', e);
});
lowkie.connection.on('connectionError', (e)=>{
console.log('error connecting to the db',e);
});
lowkie.connection.on('connecting', (dbname, options)=>{
console.log('now trying to connect to db');
});
lowkie.connection.once('connected', (db, options)=>{
console.log('now connected to db');
const UserSchema = lowkie.Schema({
email:String,
username:String,
age:Number,
});
const User = lowkie.model('User',UserSchema);
User.insert({
email:'test@domain.com',
username:'testuser',
age:30,
invalidProp:'whatever',
})
.then(newuser => {
console.log({ newuser });
})
.catch(e => {
console.log(e);
});
User.insert([
{
email:'john@domain.com',
username:'jsmith',
age:37,
},
{
email:'jane@domain.com',
username:'jdoe',
age:45,
},
{
email:'chris@domain.com',
username:'clane',
age:17,
},
])
.then((newusers)=>{
console.log(newusers);
})
.catch(e =>{
console.log(e);
})
let userQueryResults = User.find({ id: { '$gte': 1 } });
console.log({userQueryResults})
});
Development
Make sure you have grunt installed
$ npm i -g grunt-cli jsdoc-to-markdown
For generating documentation
$ grunt doc
$ jsdoc2md lib/**/*.js index.js > doc/api.md
Notes
Testing
$ npm i
$ grunt test
Contributing
fork and create a pull request!
License
MIT