New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

knex.raw in whereNot #1402

Closed
ozum opened this Issue May 12, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@ozum
Contributor

ozum commented May 12, 2016

Hi,

knex.raw() in whereNot() function swallows not keyword.

// Generates: select * from "table" where "is_active"
// Expected: select * from "table" where not "is_active"

knex
    .select('*')
    .from('table')
    .whereNot( knex.raw('??', 'is_active') );

Although I can make another query by hand easily, my code works on an AST generated by a RQL parser. As a result both a=1&is_active and a=1&not(is_active) RQL queries generates same SQL.

Is this behavior by design or a bug?

Best Regards,

@elhigu elhigu added the bug label May 12, 2016

@elhigu

This comment has been minimized.

Collaborator

elhigu commented May 12, 2016

As far as I know sounds like a bug.

@elhigu

This comment has been minimized.

Collaborator

elhigu commented May 12, 2016

This could be also one workaround:

knex.select('*').from('table').whereNot(function () { this.where(knex.raw('??', ['is_active'])) }).toQuery();
// select * from "table" where not ("is_active")

But yep this really should be fixed...

@elhigu elhigu added the PR please label May 12, 2016

@ozum

This comment has been minimized.

Contributor

ozum commented May 13, 2016

@elhigu Thank you for your response. Since my query is generated by AST, unfortunately I can't use workarounds.

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