Guarda y lee datos con la base NoSQL integrada
Total.js incluye una base de datos NoSQL integrada. NOSQL('name') abre el fichero databases/name.nosql y lo crea la primera vez que se usa. Las operaciones devuelven un builder: encadena .where() y termina con .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');
};