It is a small, secure and fast ORM for indexedDB. Created for projects who needed to encapsule their Object Stores into models and a readable API for comunication with the DB.
It is using Web Workers for isolate de access to DB from the default thread. Look at the articles in the bottom of this document and see why it's good to your project.
Just run:
$ npm i --save ant-orm
If you aren't using npm and prefer import, junt download in the dist
folder the ANT.js
file and place into your HTML like this:
<script src="/path/to/ANT.js"></script>
Than you can copy the workers folder
and import to your project.
For building this projet is simples:
$ npm run build
ANT.init({
databaseName: "DATABASE NAME",
workersPath: "/path/to/workers",
version: 1, //version of DB
modelsPaths: {
User: "/models/users.js" //Name of your model and path to your model
}
});
Just create a js file:
class User extends ANT.Model {
get columns(){
return this.setColumns({
id: { type: ANT.TYPES.NUMBER, unique: true },
name: { type: ANT.TYPES.STRING },
active: { type: ANT.TYPES.BOOL, defaultValue: true }
});
}
}
const number = ANT.TYPES.NUMBER;
const string = ANT.TYPES.STRING;
const boolean = ANT.TYPES.BOOL;
const date = ANT.TYPES.DATE;
let user = new Ant.User({
id: 1,
name: "Ricardo Zorzal"
})
let user = new Ant.User({
id: 1,
name: "Ricardo Zorzal"
});
await user.persist();
let user = await Ant.User.create({
id: 1,
name: "Ricardo Zorzal"
})
let user = await Ant.User.create({
id: 1,
name: "Ricardo Zorzal"
});
user = await user.update({
name: "Ricardo Zorzal Davila"
});
let user = await Ant.User.create({
id: 1,
name: "Ricardo Zorzal"
});
await user.destroy();
let users = await Ant.User.findAll({
name: "Ricardo Zorzal"
});
let users = await Ant.User.findAll({
name: {
"$eq": "equals",
"$ne": "not equals",
"$gt": "greater than",
"$gte": "greater than equals",
"$lt": "less than",
"$lte": "less than equals",
"$btw": "between",
"$btwe": "between equals",
"$in": "IN",
"$like": "LIKE",
"$notLike": "NOT LIKE"
}
});
1- http://blog.teamtreehouse.com/using-web-workers-to-speed-up-your-javascript-applications
2- https://developer.mozilla.org/docs/Web/API/Worker
Fast and Secure
Please if you have problems, ideias or whatever use the issue board on github. We are always waiting for a new Pull Request.