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

feat: add tableOptions parameter for inheritance on knex adapter options to pass on knex builder #3539

Open
wants to merge 2 commits into
base: dove
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/api/databases/knex.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The Knex specific adapter options are:
- `Model {Knex}` (**required**) - The KnexJS database instance
- `name {string}` (**required**) - The name of the table
- `schema {string}` (_optional_) - The name of the schema table prefix (example: `schema.table`)
- `tableOptions {only: boolean` (_optional_) - For PostgreSQL only. Argument for passing options to knex db builder. ONLY keyword is used before the tableName to discard inheriting tables' data. (https://knexjs.org/guide/query-builder.html#common)

The [common API options](./common.md#options) are:

Expand Down
4 changes: 2 additions & 2 deletions packages/knex/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ export class KnexAdapter<
}

db(params?: ServiceParams) {
const { Model, name, schema } = this.getOptions(params)
const { Model, name, schema, tableOptions } = this.getOptions(params)

if (params && params.transaction && params.transaction.trx) {
const { trx } = params.transaction
// debug('ran %s with transaction %s', fullName, id)
return schema ? (trx.withSchema(schema).table(name) as Knex.QueryBuilder) : trx(name)
}

return schema ? (Model.withSchema(schema).table(name) as Knex.QueryBuilder) : Model(name)
return schema ? (Model.withSchema(schema).table(name) as Knex.QueryBuilder) : Model(name, tableOptions)
}

knexify(knexQuery: Knex.QueryBuilder, query: Query = {}, parentKey?: string): Knex.QueryBuilder {
Expand Down
3 changes: 3 additions & 0 deletions packages/knex/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export interface KnexAdapterOptions extends AdapterServiceOptions {
Model: Knex
name: string
schema?: string
tableOptions?: {
only?: boolean
}
}

export interface KnexAdapterTransaction {
Expand Down