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

adjustments for knex v1 and v2 #15

Merged
merged 3 commits into from Mar 28, 2023

Conversation

falkenhawk
Copy link
Member

@falkenhawk falkenhawk commented Mar 23, 2023

adjustments for knex v1 and v2

knex v1+ changed the return values when .returning() clause is used (affecting postgres), before it returned array of primitive values if only 1 column was selected to be returned (e.g. [1] for .returning('id')) but now it always returns objects (e.g. [{ id: 1 }] for .returning('id')).

Slightly reorganized InsertOperation, instead of calling createModels in doExecute() (right after onRawResult hook) and having "empty" model instances created there, possibly with undefined / declared default properties which would later overwrite input models in InsertOperation.onAfter1, offload the handling to InsertOperation.onAfter1, which now uses also setDatabaseJson, same as createModels function, to be consistent.

Additionally, adjusted $parseDatabaseJson in GraphInsert integration tests, to only parse boolean values when they are present in json.

related change in knex v1.0: knex/knex#4471

introduced new (or missing) knex querybuilder's methods

to make shapes of both querybuilders as close to each other as possible.
Most of the methods were introduced in knex v1.

  • fromRaw
  • whereLike
  • andWhereLike
  • orWhereLike
  • whereILike
  • andWhereILike
  • orWhereILike
  • withMaterialized
  • withNotMaterialized
  • jsonExtract
  • jsonSet
  • jsonInsert
  • jsonRemove
  • whereJsonObject
  • orWhereJsonObject
  • andWhereJsonObject
  • whereNotJsonObject
  • orWhereNotJsonObject
  • andWhereNotJsonObject
  • whereJsonPath
  • orWhereJsonPath
  • andWhereJsonPath

and one new JoinBuilder method - andOnJsonPathEquals (referencing knex's JoinClause method of the same name)

related: knex/knex#4859 knex/knex#5044

whereJson(Not)SupersetOf / whereJson(Not)SubsetOf are now supported by knex >= 1.0, but for now
objection handles them differently and only for postgres.
Changing them to utilize knex methods directly may require a major version bump and upgrade guide.

Added a test for checking JoinBuilder methods to be inline with knex's JoinClause.

Fixed incorrect checking QueryBuilder methods if they are inline with knex's QueryBuilder.

Added typings for new methods.

Bumped knex peerDependency from >=0.95.13 to >=1.0.1 because of new methods.

@falkenhawk falkenhawk self-assigned this Mar 23, 2023
@falkenhawk
Copy link
Member Author

falkenhawk commented Mar 23, 2023

there is a bunch of postgres tests failing after the knex upgrade, same as in Vincit#2353
Edit: fixed in this PR

knex v1+ changed the return values when `.returning()` clause is used (affecting postgres), before it returned array of primitive values if only 1 column was selected to be returned (e.g. `[1]` for `.returning('id')`) but now it always returns objects (e.g. `[{ id: 1 }]` for `.returning('id')`).

Slightly reorganized `InsertOperation`, instead of calling `createModels` in `doExecute()` (right after `onRawResult` hook) and having "empty" model instances created there, possibly with undefined / declared default properties which would later overwrite input models in `InsertOperation.onAfter1`, offload the handling to `InsertOperation.onAfter1`, which now uses also `setDatabaseJson`, same as `createModels` function, to be consistent.

Additionally, adjusted `$parseDatabaseJson` in `GraphInsert` integration tests, to only parse boolean values when they are present in `json`.

related change in knex v1.0: knex/knex#4471
to make shapes of both querybuilders as close to each other as possible.
Most of the methods were introduced in knex v1.
- `fromRaw`
- `whereLike`
- `andWhereLike`
- `orWhereLike`
- `whereILike`
- `andWhereILike`
- `orWhereILike`
- `withMaterialized`
- `withNotMaterialized`
- `jsonExtract`
- `jsonSet`
- `jsonInsert`
- `jsonRemove`
- `whereJsonObject`
- `orWhereJsonObject`
- `andWhereJsonObject`
- `whereNotJsonObject`
- `orWhereNotJsonObject`
- `andWhereNotJsonObject`
- `whereJsonPath`
- `orWhereJsonPath`
- `andWhereJsonPath`
and one new `JoinBuilder` method - `andOnJsonPathEquals` (referencing knex's `JoinClause` method of the same name)

`whereJson(Not)SupersetOf` / `whereJson(Not)SubsetOf` are now supported by knex >= 1.0, but for now
objection handles them differently and only for postgres.
Changing them to utilize knex methods directly may require a major version bump and upgrade guide.

Added a test for checking JoinBuilder methods to be inline with knex's JoinClause.

Fixed incorrect checking QueryBuilder methods if they are inline with knex's QueryBuilder.

Added typings for new methods.

Bumped knex `peerDependency` from `>=0.95.13` to `>=1.0.1` because of new methods.
@falkenhawk falkenhawk changed the title bump typescript, knex and @types/node to get rid of typing errors in test:typings adjustments for knex v1 and v2 Mar 28, 2023
Copy link
Member

@flipace flipace left a comment

Choose a reason for hiding this comment

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

Ahoy, Captain Code-Diver! 🏊‍♂️

Once again, you've plunged into the abyss of an external library to unearth a fix for an issue so exotic, it could have been featured on an episode of "Rare Code Mysteries"! 🕵️‍♂️🔍

Your unmatched dedication to addressing the needs of the niche-est of the niche users is truly commendable. As always, your valiant efforts shall be remembered in the hallowed halls of our git history. 🏆

So, with a mixture of amusement, awe, and a pinch of "do we really need this?", I approve this PR! 🎉

May your coding trident continue to pierce the depths of the unknown! ⚓️💻

@falkenhawk falkenhawk merged commit 06c9746 into master Mar 28, 2023
3 checks passed
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.

None yet

2 participants