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

Exposing the query builder #87

Closed
leebenson opened this issue Nov 23, 2016 · 8 comments
Closed

Exposing the query builder #87

leebenson opened this issue Nov 23, 2016 · 8 comments

Comments

@leebenson
Copy link

leebenson commented Nov 23, 2016

I'm trying to figure out how to access the query builder object instead of the resolved promise containing row data that's returned by .find().

I'm using this lib vs. my own 'raw' knex connection to map feathers' query operators, and its handling of pagination, etc. At the same time, I often need more granular access to what's returned in a typical .find -- left joins, mapping hasMany relationships, scoping SQL to a transaction, etc.

It'd be super handy to have a generic query method that could return the QB instead of the raw results... is there a best practice for doing that?

@daffl
Copy link
Member

daffl commented Nov 23, 2016

Good call. We're doing that for RethinkDB already where createQuery(query) returns a non-paginated query from a query. Shouldn't be too difficult to add to this one. Then it would be possible to create more complex queries in a before hook and set hook.params.knex = query;.

@leebenson
Copy link
Author

Sounds great, thanks!

@daffl
Copy link
Member

daffl commented Nov 30, 2016

This is done in 2.6.0. Documentation can be found in https://docs.feathersjs.com/v/auk/databases/knexjs.html#customizing-the-query

@ghost
Copy link

ghost commented Jan 9, 2017

Following on this, in order to be able to make joins, createQuery and knexify should scope queries to this.table so we don't end up with "ambiguous" column reference.

Ex:
In createQuery

let q = this.db().select(['*']);
// should be
let q = this.db().select([`${this.table}.*`]);

What do you guys think ?

@daffl
Copy link
Member

daffl commented Jan 9, 2017

@shadowRR Makes sense. Can you submit a PR?

@ghost
Copy link

ghost commented Jan 10, 2017

Yes, no problem. After further testing, only createQuery should scope the current table for the select part of the query. For knexify, it is up to the user to scope it's "where", "or"... conditions.

@roelvan
Copy link

roelvan commented Jan 25, 2018

@shadowRR could you show me an example of how to do a join using the createQuery function? Cannot make it work. Thanks in advance.

@carcinocron
Copy link

@roelvan can you post an error message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants