ForgeTotal.js 5
it

Total.js 5

Archiviare e leggere dati con il database NoSQL integrato

Total.js 5 · total5@0.0.19 nosqldatabaseactions Eseguita con Total.js 5

Total.js include un database NoSQL integrato. NOSQL('name') apre il file di database databases/name.nosql e lo crea al primo utilizzo. Le operazioni restituiscono un builder: concatena .where() e termina con .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');
};