Skip to content

Commit

Permalink
fix: objection v3 and knex v1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Olavi Mustanoja committed May 24, 2022
1 parent 6e9171a commit 53004cb
Show file tree
Hide file tree
Showing 6 changed files with 792 additions and 1,000 deletions.
1 change: 1 addition & 0 deletions lib/operations/CursorPageOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ function whereMore(builder, keyset) {
function _whereMore(builder, comparisons, composites) {
const comparison = comparisons[0];
composites = [comparison, ...composites];

const op = comparison.order === 'asc' ? '>' : '<';

builder.andWhere(function () {
Expand Down
6 changes: 5 additions & 1 deletion lib/operations/OrderByOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OrderByOperation extends Operation {
}

onBuild(builder) {
builder.orderBy(this.column, this.order, true);
builder.orderBy(this.column, this.order, this.nulls, true);
}

get column() {
Expand All @@ -21,6 +21,10 @@ class OrderByOperation extends Operation {
get order() {
return this.args[1];
}

get nulls() {
return this.args[2];
}
}

module.exports = OrderByOperation;
6 changes: 3 additions & 3 deletions lib/query-builder/CursorQueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ module.exports = function (options, Base) {
return addOperation(this, new OrderByExplicitOperation(), args);
}

orderBy(column, order, native = false) {
orderBy(column, order, nulls = '', native = false) {
if (native) {
return super.orderBy(column, order, native);
return super.orderBy(column, order, nulls, native);
}

return addOperation(this, new OrderByOperation(), [column, order]);
return addOperation(this, new OrderByOperation(), [column, order, nulls]);
}

clear(selector) {
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"test": "mocha --require @babel/register",
"test:sqlite": "CLIENT=sqlite3 mocha --require @babel/register",
"test:pg": "CLIENT=pg mocha --require @babel/register",
"test:tav": "tav",
"lint": "eslint --fix \"index.js\" \"lib/**/*.js\" \"test/**/*.js\"",
Expand All @@ -29,12 +30,12 @@
"chai-as-promised": "^7.1.1",
"eslint": "^4.19.1",
"eslint-plugin-mocha": "^5.0.0",
"knex": "^0.15.0",
"knex": "^2",
"mocha": "^5.2.0",
"mysql": "^2.17.1",
"objection": "^2.0.0",
"pg": "^7.4.3",
"sqlite3": "^4.0.1",
"objection": "^3",
"pg": "^8.7.3",
"sqlite3": "^5.0.0",
"test-all-versions": "^4.1.1"
},
"dependencies": {
Expand Down
20 changes: 15 additions & 5 deletions test/ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ module.exports = knex => {
});

it('order by ref - 2 columns', async () => {
const query = Movie.query()
let query = Movie.query()
.orderByCoalesce(ref('ref.data:none').castText(), 'desc', raw('?', ''))
.orderBy('movies.id', 'asc')
.joinEager('ref');
.orderBy('movies.id', 'asc');

if (query.withGraphJoined) {
query = query.withGraphJoined('ref');
} else {
query = query.joinEager('ref');
}

const expected = await query.clone();

Expand All @@ -88,11 +93,16 @@ module.exports = knex => {
}
}

const query = CaseMovie.query()
.joinEager('ref')
let query = CaseMovie.query()
.orderByCoalesce(ref('ref.data:title').castText(), 'desc')
.orderBy('movies.id', 'asc');

if (query.withGraphJoined) {
query = query.withGraphJoined('ref');
} else {
query = query.joinEager('ref');
}

const expected = await query.clone();

let res = await query.clone().limit(5).cursorPage();
Expand Down
Loading

0 comments on commit 53004cb

Please sign in to comment.