feathers-sequelize
feathers-sequelize copied to clipboard
Support withSchema [with PR]
I'd like to dynamically change schema based on request params, which can be done in Sequelize by calling the model with withSchema
, similarly to withScope
usage which is already supported by feathers-sequelize.
Is that something you would accept in feathers-sequelize? I can propose a PR.
At the currently supported version of sequelize, it would be just schema
which is supposed to be deprecated by withSchema
in sequelize 7
I also see that you are currently getting to a new major release. I'd love to slip this addition in :)
I'm not sure how to structure the addition though. I see that applyScope
is deprecated in favor of ModelWithScope
, which is being used as a model in all DB methods.
If I wanted to add schema
support, I either can:
- add a new function similar to applyScope, like
applySchema
- alter the
ModelWithScope
to be loosened toModelWithScopeAndSchema
which I really don't like for its smell, or - assume that support for more sequelize props can be added in the future, and make the Model function more generic such as:
ModelWithSequelizeParams(params: ServiceParams) {
const Model = this.getModel(params)
# apply scope if present in params
# apply schema if present in params
# here be space for future additions
return Model
}
and then use this in all DB methods.
What do you think?
I am sorry for the slow response on this! I will investigate Sequelize's withSchema
options and see if we can get that added.
Thanks! I can see that you've got a lot on your hands (don't we all :D) so I completely understand, no rush :) I've been already using the change i proposed in the PR in production (using patch-package) and it's been working good so far.