Lagra och läs data med den inbyggda NoSQL-databasen
Total.js levereras med en inbyggd NoSQL-databas. NOSQL('name') öppnar databasfilen databases/name.nosql och skapar den vid första användningen. Operationer returnerar en builder: kedja .where() och avsluta med .callback(function(err, response) {}).
NEWACTION('Notes/insert', {
name: 'Insert a note',
input: '*text:String',
action: function($, model) {
model.id = UID();
NOSQL('notes').insert(model).callback(function() {
$.success(model.id);
});
}
});
NEWACTION('Notes/query', {
name: 'List notes',
action: function($) {
NOSQL('notes').find().callback(function(err, response) {
$.callback(response);
});
}
});exports.install = function() {
ROUTE('POST /notes/ --> *Notes/insert');
ROUTE('GET /notes/ --> *Notes/query');
};