Daten mit der eingebauten NoSQL-Datenbank speichern und lesen
Total.js bringt eine eingebaute NoSQL-Datenbank mit. NOSQL('name') öffnet die Datenbankdatei databases/name.nosql und legt sie bei der ersten Nutzung an. Operationen liefern einen Builder: verkette .where() und schließe mit .callback(function(err, response) {}) ab.
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');
};