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

Add support for setting schema in hook params #255

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ __Options:__

Returns a KnexJS query with the [common filter criteria](https://docs.feathersjs.com/api/databases/querying.html) (without pagination) applied.

### params.knex

When making a [service method](https://docs.feathersjs.com/api/services.html) call, `params` can contain an `knex` property which allows to modify the options used to run the KnexJS query. See [customizing the query](#customizing-the-query) for an example.
### Params Operators
When making a [service method](https://docs.feathersjs.com/api/services.html) call, `params` can contain:
- **`knex`** - Modifies the options used to run the KnexJS query. See [customizing the query](#customizing-the-query) for an example.
- **`schema`** - Database schema to use with the query (e.g. `public`) See [`withSchema`](http://knexjs.org/#Builder-withSchema) documentation. Overrides service's `schema` option.


## Example
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class Service extends AdapterService {
// NOTE (EK): We need this method so that we return a new query
// instance each time, otherwise it will reuse the same query.
db (params = {}) {
const { knex, table, schema, fullName } = this;
const { knex, table, fullName } = this;
const schema = params.schema || this.schema;
if (params.transaction) {
const { trx, id } = params.transaction;
debug('ran %s with transaction %s', fullName, id);
Expand Down