Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Auto adding placeholders to set, where #3

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

fliespl commented Mar 17, 2012

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"]

Added autoadding placeholders and converting null. Added support for
set('x', '1'), set('x', 'IS', null), set('x', '>', a)

fliespl commented Mar 17, 2012

There is a typo in todo:

Todo: add placeholder support for expressions (not extensions).

Owner

hiddentao commented Mar 19, 2012

I like the idea of the getParams() function to retrieve the parameters you passed in.

We'd need to modify the Coffeescript source and add tests before merging this into trunk.

Owner

hiddentao commented Apr 8, 2013

This pull request is no longer valid because master has changed. Squel builders can now be flexibly configured and extended.

Adding the improved set() method and the getParams() method can now be done by customizing the relevant building Block used in the query builder without modifying Squel internals. However, if enough people find these methods useful then they can be added to core.

Am closing this for now.

@hiddentao hiddentao closed this Apr 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment