ForgeTotal.js 5
nl

Total.js 5

Gegevens opslaan en lezen met de ingebouwde NoSQL-database

Total.js 5 · total5@0.0.19 nosqldatabaseactions Uitgevoerd met Total.js 5

Total.js heeft een ingebouwde NoSQL-database. NOSQL('name') opent het databasebestand databases/name.nosql en maakt het bij eerste gebruik aan. Bewerkingen geven een builder terug: koppel .where() en sluit af met .callback(function(err, response) {}).

definitions/notes.js
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);
		});
	}
});
controllers/notes.js
exports.install = function() {
	ROUTE('POST /notes/ --> *Notes/insert');
	ROUTE('GET /notes/ --> *Notes/query');
};