Skip to content
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
Closed

knex.raw in whereNot #1402

ozum opened this issue May 12, 2016 · 3 comments

Comments

@ozum
Copy link
Contributor

@ozum 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
Copy link
Member

@elhigu elhigu commented May 12, 2016

As far as I know sounds like a bug.

@elhigu
Copy link
Member

@elhigu 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...

@ozum
Copy link
Contributor Author

@ozum 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants