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

Feature Request: Clone Method for Chains #5

Closed
dominicbarnes opened this Issue Oct 31, 2012 · 4 comments

Comments

Projects
None yet
2 participants

Just a small feature request for the API. I'd like a clone method that would take an existing chain and return a functional duplicate of the working SQL command.

My use-case is like this: I have a lib that's generating a SELECT statement for single items by ID, as well as the list of all in a collection. Having to specify my fields/tables/etc is kinda cumbersome and creating a wrapper function is not very elegant either.

For example:

var select = squel.select()
    .field("id")
    .field("name")
    .from("users", "u");

var single = select.clone()
    .where("id = ?")
    .toString();

var list = select.clone()
    .limit(10)
    .offset(0)
    .toString();

This is a trivial example, but after adding joins and other conditions, this becomes a much more friendly way to approach similar queries.

Owner

hiddentao commented Nov 1, 2012

This is a good idea. In the interim have you tried using normal cloning methods? http://stackoverflow.com/a/5344074

I have not yet, I'll give it a spin and report back for other's reference.

hiddentao added a commit that referenced this issue Nov 3, 2012

All builders now have a clone() method.
Fixed test setup error whereby tests being run multiple times.

Simplified Makefile test file spec.

refs #5
Owner

hiddentao commented Nov 3, 2012

Latest version (1.0.5) now comes with a clone() method available to all query builders (but not Expression builders yet, unfortunately)

Stellar, I'll just be using that then :)

Thanks!

@hiddentao hiddentao closed this Dec 5, 2012

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