Skip to content

Commit

Permalink
Merge pull request #15 from ovos/upgrade-typescript-knex-node-types
Browse files Browse the repository at this point in the history
adjustments for knex v1 and v2
  • Loading branch information
falkenhawk committed Mar 28, 2023
2 parents 7e8a2bd + 2a4c137 commit 06c9746
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 127 deletions.
4 changes: 4 additions & 0 deletions lib/queryBuilder/JoinBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class JoinBuilder extends QueryBuilderOperationSupport {
return this.addOperation(new KnexOperation('andOnNotBetween'), args);
}

andOnJsonPathEquals(...args) {
return this.addOperation(new KnexOperation('andOnJsonPathEquals'), args);
}

onVal(...args) {
return this.addOperation(new KnexOperation('onVal'), args);
}
Expand Down
9 changes: 7 additions & 2 deletions lib/queryBuilder/QueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,12 +1274,17 @@ async function chainHooks(promise, builder, func) {
}

function createModels(result, builder) {
const modelClass = builder.resultModelClass();

if (result === null || result === undefined) {
return null;
}

if (builder.isInsert()) {
// results are applied to input models in `InsertOperation.onAfter1` instead.
return result;
}

const modelClass = builder.resultModelClass();

if (Array.isArray(result)) {
if (result.length && shouldBeConvertedToModel(result[0], modelClass)) {
for (let i = 0, l = result.length; i < l; ++i) {
Expand Down
107 changes: 107 additions & 0 deletions lib/queryBuilder/QueryBuilderBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class QueryBuilderBase extends QueryBuilderOperationSupport {
return this.addOperation(new KnexOperation('fromJS'), args);
}

fromRaw(...args) {
return this.addOperation(new KnexOperation('fromRaw'), args);
}

into(...args) {
return this.addOperation(new KnexOperation('into'), args);
}
Expand Down Expand Up @@ -281,6 +285,30 @@ class QueryBuilderBase extends QueryBuilderOperationSupport {
return this.addOperation(new KnexOperation('orWhereNotBetween'), args);
}

whereLike(...args) {
return this.addOperation(new KnexOperation('whereLike'), args);
}

andWhereLike(...args) {
return this.addOperation(new KnexOperation('andWhereLike'), args);
}

orWhereLike(...args) {
return this.addOperation(new KnexOperation('orWhereLike'), args);
}

whereILike(...args) {
return this.addOperation(new KnexOperation('whereILike'), args);
}

andWhereILike(...args) {
return this.addOperation(new KnexOperation('andWhereILike'), args);
}

orWhereILike(...args) {
return this.addOperation(new KnexOperation('orWhereILike'), args);
}

groupBy(...args) {
return this.addOperation(new KnexOperation('groupBy'), args);
}
Expand Down Expand Up @@ -481,6 +509,14 @@ class QueryBuilderBase extends QueryBuilderOperationSupport {
return this.addOperation(new KnexOperation('withRecursive'), args);
}

withMaterialized(...args) {
return this.addOperation(new KnexOperation('withMaterialized'), args);
}

withNotMaterialized(...args) {
return this.addOperation(new KnexOperation('withNotMaterialized'), args);
}

whereComposite(...args) {
return this.addOperation(new WhereCompositeOperation('whereComposite'), args);
}
Expand Down Expand Up @@ -513,13 +549,72 @@ class QueryBuilderBase extends QueryBuilderOperationSupport {
return this.addOperation(operation, args);
}

jsonExtract(...args) {
return this.addOperation(new KnexOperation('jsonExtract'), args);
}

jsonSet(...args) {
return this.addOperation(new KnexOperation('jsonSet'), args);
}

jsonInsert(...args) {
return this.addOperation(new KnexOperation('jsonInsert'), args);
}

jsonRemove(...args) {
return this.addOperation(new KnexOperation('jsonRemove'), args);
}

whereJsonObject(...args) {
return this.addOperation(new KnexOperation('whereJsonObject'), args);
}

orWhereJsonObject(...args) {
return this.addOperation(new KnexOperation('orWhereJsonObject'), args);
}

andWhereJsonObject(...args) {
return this.addOperation(new KnexOperation('andWhereJsonObject'), args);
}

whereNotJsonObject(...args) {
return this.addOperation(new KnexOperation('whereNotJsonObject'), args);
}

orWhereNotJsonObject(...args) {
return this.addOperation(new KnexOperation('orWhereNotJsonObject'), args);
}

andWhereNotJsonObject(...args) {
return this.addOperation(new KnexOperation('andWhereNotJsonObject'), args);
}

whereJsonPath(...args) {
return this.addOperation(new KnexOperation('whereJsonPath'), args);
}

orWhereJsonPath(...args) {
return this.addOperation(new KnexOperation('orWhereJsonPath'), args);
}

andWhereJsonPath(...args) {
return this.addOperation(new KnexOperation('andWhereJsonPath'), args);
}

// 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.
whereJsonSupersetOf(...args) {
return this.addOperation(
new WhereJsonPostgresOperation('whereJsonSupersetOf', { operator: '@>', bool: 'and' }),
args
);
}

andWhereJsonSupersetOf(...args) {
return this.whereJsonSupersetOf(...args);
}

orWhereJsonSupersetOf(...args) {
return this.addOperation(
new WhereJsonPostgresOperation('orWhereJsonSupersetOf', { operator: '@>', bool: 'or' }),
Expand All @@ -538,6 +633,10 @@ class QueryBuilderBase extends QueryBuilderOperationSupport {
);
}

andWhereJsonNotSupersetOf(...args) {
return this.andWhereJsonNotSupersetOf(...args);
}

orWhereJsonNotSupersetOf(...args) {
return this.addOperation(
new WhereJsonPostgresOperation('orWhereJsonNotSupersetOf', {
Expand All @@ -556,6 +655,10 @@ class QueryBuilderBase extends QueryBuilderOperationSupport {
);
}

andWhereJsonSubsetOf(...args) {
return this.whereJsonSubsetOf(...args);
}

orWhereJsonSubsetOf(...args) {
return this.addOperation(
new WhereJsonPostgresOperation('orWhereJsonSubsetOf', { operator: '<@', bool: 'or' }),
Expand All @@ -574,6 +677,10 @@ class QueryBuilderBase extends QueryBuilderOperationSupport {
);
}

andWhereJsonNotSubsetOf(...args) {
return this.whereJsonNotSubsetOf(...args);
}

orWhereJsonNotSubsetOf(...args) {
return this.addOperation(
new WhereJsonPostgresOperation('orWhereJsonNotSubsetOf', {
Expand Down
2 changes: 1 addition & 1 deletion lib/queryBuilder/operations/InsertOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class InsertOperation extends QueryBuilderOperation {
// If the user specified a `returning` clause the result may be an array of objects.
// Merge all values of the objects to our models.
for (let i = 0, l = this.models.length; i < l; ++i) {
this.models[i].$set(ret[i]);
this.models[i].$setDatabaseJson(ret[i]);
}
} else {
// If the return value is not an array of objects, we assume it is an array of identifiers.
Expand Down

0 comments on commit 06c9746

Please sign in to comment.