hiddentao/squel — pull request #3 by fliespl (2012-03-17 10:43:26+00:00)
Title: Auto adding placeholders to set, where

Added autoadding placeholders and converting null values.
Added support for set('x', '1'), set('x', 'IS', null), set('x', '>', a) for clarity
Added getParams() function which returns params to pass to sqlite database query.

Todo: add placeholder support for extensions

I used it for my personal project (chrome, firefox extensions which are using sqlite), maybe you find use for it.

Examples:

var query1 = squel.update().table('library').set('x', 'x').set('abc', null).set('cde', undefined).where('x = 1').where("y", "2").where("y", ">", "3");
var query2 = squel.select().from('library').where('x = 1').where("y", "2").where("y", ">", "3");
var query3 = squel.insert().into('library').set('x', '1').set("y", "2").set("z", "3");
var query4 = squel.delete().from('library').where('x = 1').where("y", "2").where('abc', '<>', 'x');

Results:

console.log(query1.toString(), query1.getParams());
console.log(query2.toString(), query2.getParams());
console.log(query3.toString(), query3.getParams());
console.log(query4.toString(), query4.getParams());

UPDATE library SET x = ?1, abc = NULL, cde = NULL WHERE (x = 1) AND (y = ?2) AND (y > ?3) ["x", "2", "3"]
SELECT * FROM library WHERE (x = 1) AND (y = ?1) AND (y > ?2) ["2", "3"]
INSERT INTO library (x, y, z) VALUES (?1, ?2, ?3) ["1", "2", "3"]
DELETE FROM library WHERE (x = 1) AND (y = ?1) ["2"]