You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Explain what is your use case
I'd like to always transform Knex results using a custom function. I.e. instead of needing to write resultsToEntities(await query), I'd like Knex to pass the results of queries through resultsToEntities automatically. I don't think it's possible using the start or query-response events.
Explain what kind of feature would support this
This should be a common use-case, I'd assume a lot of people want to do some custom processing with Knex's results.
Give some API proposal, how the feature should work
Have a hook like "transformResults", then it would be easier to write a model class like:
class Model {
query() {
return knex
.from(this.tableName)
.transformResults(resultsToEntities);
}
}
Then I can do await Model.query().select(...); instead of resultsToEntities(await Model.query().select(...));.
Environment
Knex version: 3.1.0
Database + version: Postgres 16.1
OS: Ubuntu
Feature discussion / request
Explain what is your use case
I'd like to always transform Knex results using a custom function. I.e. instead of needing to write
resultsToEntities(await query)
, I'd like Knex to pass the results of queries throughresultsToEntities
automatically. I don't think it's possible using thestart
orquery-response
events.Explain what kind of feature would support this
This should be a common use-case, I'd assume a lot of people want to do some custom processing with Knex's results.
Give some API proposal, how the feature should work
Have a hook like "transformResults", then it would be easier to write a model class like:
Then I can do
await Model.query().select(...);
instead ofresultsToEntities(await Model.query().select(...));
."Objection" automatically transforms query results, but I think it does so by creating its own query builder with the same interface as Knex (https://github.com/Vincit/objection.js/blob/main/lib/queryBuilder/QueryBuilderBase.js). A
transformResults
method would make this much easier to do.The text was updated successfully, but these errors were encountered: