is a library that provides an abstraction/interface ORM(Object Relational Mapper), in order to facilitate the manipulation of data registered in the localstorage.
Special thanks to the lala-web-sql project (https://github.com/jefersondaniel/lala-web-sql) that inspired the architecture for this project.
var users = new StorageModel('User');
users
// out: StorageModel {model: "User", columns: Array[0], fields: Object}users.create({
name: 'Geroudo',
age: 18
});
// out: Object {name: "Geroudo", age: 18, id: 1, status: 1}
users.create({
name: 'Sterferson',
age: 20
});
// out: Object {name: "Sterferson", age: 20, id: 2, status: 1}users.all().get(); // or users.all().toArray();
users.find(1); // find by id
users.find({name: 'Geroudo'});
users.all().orderBy('age', 'dec').each(function(user){
console.log(user);
});users.update({
name: 'Wellington'
}, 1);
// out: Object {name: "Wellington", age: 18, id: 1, status: 1}
users.where('id', '>', 1).update({
'status': 0
});users.remove(1); // In this case only the status for 0
// out: Object {name: "Wellington", age: 18, id: 1, status: 0}
users.remove(1, true); // Force a removal// counting
users.count();
users.where('age', '>', 18).count();
// properties
users.model // out: "User"
users.columns // out: ["name", "age", "id", "status"]
// Selection limit
users.all().first();
users.where('age', '>', 18).take(2);users.dropModel(); // Clear the table
users.drop(); // Clear the localstorageThis project is licensed under the MIT License. This means you can use and modify it for free in private or commercial projects.
It is required node.js and npm
$ git clone https://github.com/Wellington475/StorageModel
$ npm install