Exemplo n.º 1
0
AuthorCollection.findOne("SELECT COUNT(*) as `count` FROM `author` WHERE name = '" + author.name + "'", function(err, data) {
	var count = data.get('count');

	if (count < 1) {
		//Create model
		var knygaModel = AuthorCollection.createModel(author);
		knygaModel.create(function(err) {
			console.log(err);
		});
	}
});
Exemplo n.º 2
0
var mysql = require('mysql'),
	lightOrm = require('light-orm');

lightOrm.driver = mysql.createConnection(require('./connection.json'));
lightOrm.driver.connect();

var author = {
	name: "Oleksandr Knyga",
	description: "Rational light ORM"
};

var AuthorCollection = new lightOrm.Collection('author');

//Select by object
AuthorCollection.findOne({
	id: 1
}, function(err, model) {
	//Get all attributes
	console.log(model.getAll());
	//{ id: 1, name: 'James Bond', description: 'Agent 007' }
});

//Select by query
AuthorCollection.findOne("SELECT * FROM `author` WHERE id = 1", function(err, model) {
	console.log(model.getAll());
	//{ id: 1, name: 'James Bond', description: 'Agent 007' }
});


//Get scalar from select
AuthorCollection.findOne("SELECT COUNT(*) as `count` FROM `author` WHERE name = '" + author.name + "'", function(err, data) {