Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Chaining improvements (make chains cloneable) #324

@jamesrom

Description

@jamesrom

It would be great if you could do something like

var query = knex('users').select('username');
var admins = query.where('account_type', 0);
var me = query.where('username', 'jamesrom');
var others = query.where('account_type', '>', 0);

Notice how I'm reusing query with different where clauses. This would mean that the query builder methods would return a new query builder object, not modify the original.

An alternative and simplier solution could be a .clone() method (similar to jQuery, momentjs, etc) that returns a clone of the query builder object.

var query = knex('users').select('username');
var admins = query.clone().where('account_type', 0);
var me = query.clone().where('username', 'jamesrom');
var others = query.clone().where('account_type', '>', 0);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions