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

fix(knex): Add tableOptions parameter for inheritance on knex adapter options to pass on knex builder #3539

Merged
merged 3 commits into from
Feb 6, 2025

Conversation

fidelio314
Copy link
Contributor

Add support on knex adapter to passe tableOptions on the Knex builder in order to support the option ONLY that discard the inheriting tables - For PostgreSQL only

Today the feathesjs-knex package was not able to pass the option:

{
  only: true
}

Here is the knex doc: https://knexjs.org/guide/query-builder.html#common

I propose a new knex specific adapter option called: tableOptions to be used on the getOptions method of the service class.

this can be passed on the db method on the knex adapter and therfore to the

Model(name, tableOptions)

@fidelio314 fidelio314 changed the title feat: add tableOptions parameter on knex adapter options to pass on knex builder feat: add tableOptions parameter for inheritance on knex adapter options to pass on knex builder Sep 23, 2024

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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it work if the tableOptions has not been provided, I would prefer we check it before passing the tableOptions as parameter on the knex adapter options like this:-

let queryBuilder: Knex.QueryBuilder;
  if (params?.transaction?.trx) {
    const { trx } = params.transaction;
    queryBuilder = schema ? trx.withSchema(schema).table(name) : trx.table(name);
  } else {
    queryBuilder = schema ? Model.withSchema(schema).table(name) : Model.table(name);
  }

  // Apply tableOptions if provided
  if (tableOptions) {
    queryBuilder = queryBuilder.withOptions(tableOptions); // Adjust this if .withOptions() isn't the exact method for tableOptions
  }
  return queryBuilder;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the
Model(name, tableOptions)

has already the tableOptions that can undefined. (its tha case now)
i am just proposign to pass them and then allow to have this property reach the knex mode.
no the ONLY postgres query is impossible to have though feathers.

@daffl daffl changed the title feat: add tableOptions parameter for inheritance on knex adapter options to pass on knex builder fix(knex): Add tableOptions parameter for inheritance on knex adapter options to pass on knex builder Feb 6, 2025
@daffl daffl merged commit ba5621b into feathersjs:dove Feb 6, 2025
2 checks passed
@daffl
Copy link
Member

daffl commented Feb 6, 2025

Ooops, sorry for some reason I thought the tests were failing but they just didn't have approval to run. Thank you for putting this up, it will go out with the next release.

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

Successfully merging this pull request may close these issues.

3 participants