-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
36 lines (29 loc) · 1.28 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- Welcome to Kabin! (alpha warning!)--
This is a simple JSON file database for nodejs.
The console (examples/prompt.js) has already connected to the sample database.
Connect to a directory at path var db = new kabin.JSON({path: 'data'});
Create a new record with db.insert('e', {x: 10, y: 20})
Read data from a record with db.e.x => 10
Write data to a record with d.e = {x: 1, y: 2}
db.migrate() -> migrate to latest version. db.version is the current version.
db.migrate({version: x}) -> migrate to version x. up or down depending on current version.
Put a model in db/models. See Recipe.js for an example:
{
init: function (data) {
this.data = data;
if(!this.data.saved) { this.data.saved = 0; }
},
getIngredients: function () {
return this.data.ingredients;
},
onSave: function () {
this.data.saved += 1;
return this.data;
}
}
A model must have the onSave function which defines what json-data it saves.
A JSON file with the field type, will check if such a model exists, and then create it.
See db.data.b for an example of a Recipe class instance.
Will probably make the saving more logical.
Currently to save changes to db.data.b you need to write db.data.b = db.data.b.
kabin>