0.2.16 • Published 9 years ago
just-json v0.2.16
just-json
Root object props & methods
DB = {
schemas: {
// ...listing of schemas
},
config(opts) {
// GET or SET database configs
let opts = {
path: 'stores/db',
schema: './_schemas.json'
}
},
select(collection, schema),
removeCollection(name),
emptyCollection(name),
reset()
}Collection methods
add(item)— add record to collectionsave(item)— alias for add methodget(id, fields)— retrieve record from collectionupdate(id, data)— update record with idremove(id)— remove record with idsync(data)— synchronize/replace data in current collectioncount()— get count of records in current collectionfind()— Promise-based method.find().run().then()with finder model. Search methods see bellow.
Finder methods
equals(key, val)notEqual(key, val)gt(key, val)gte(key, val)lt(key, val)lte(key, val)matches(key, reg)paginate(count, sort)one()run()
Usage example
_schemas.json
{
"currencies": {
"title": "Валюты",
"fields": [
"tag|text|Тег",
"name|text|Название"
]
},
"currates": {
"title": "Ставки валют",
"fields": [
"currency|select|Валюта",
"rate|text|Ставка",
"created_at|date|Дата"
],
"dependencies": {
"currency": "currencies:tag,name"
}
}
}app.js
const DB = require('just-json')
DB.configure({
path: 'stores/db',
schema: __dirname + '/_schemas.json'
});
// add collection
var Movie = DB.select('tosters');
// add item into "Movie" collection
let key = Movie.add({
type: 'movie',
title: 'The Godfather',
director: 'Francis Ford Coppola',
writer: 'Mario Puzo',
imdb: 9.2
});
let mov = Movie.get(key); // return value of [_id] field
console.log('\n\n', mov);
Movie.remove(key); // remove item
mov = Movie.get(key); // try to get again
console.log('\n\n', mov); // return -> null
// add a record again
let key = Movie.add({
type: 'movie',
title: 'The Godfather',
director: 'Francis Ford Coppola',
writer: 'Mario Puzo',
imdb: 9.2
});
console.log('\n\nCount is', Movie.count()); // -> 1
// test find method
Movie.find()
.matches('title', /he/i)
.matches('type', /movie/i)
.paginate(2)
.run()
.then( results => {
console.log('\n\nFind results', results);
});0.2.16
9 years ago
0.2.15
9 years ago
0.2.14
9 years ago
0.2.13
9 years ago
0.2.12
9 years ago
0.2.11
9 years ago
0.2.10
9 years ago
0.2.9
9 years ago
0.2.8
9 years ago
0.2.7
9 years ago
0.2.6
9 years ago
0.2.5
9 years ago
0.2.4
9 years ago
0.2.3
9 years ago
0.2.2
9 years ago
0.2.1
9 years ago
0.2.0
9 years ago
0.1.2
9 years ago
0.1.1
9 years ago
0.1.0
9 years ago
0.0.2
9 years ago
0.0.1
9 years ago