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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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