Skip to content

Commit

Permalink
Merge pull request #156 from balena-io-modules/number-ref-binds
Browse files Browse the repository at this point in the history
Support number references as boolean types
  • Loading branch information
Page- authored Oct 4, 2024
2 parents 116e8bb + 7ab6404 commit 947914b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"license": "BSD",
"dependencies": {
"@balena/abstract-sql-compiler": "^9.2.0",
"@balena/odata-parser": "^3.0.8",
"@types/lodash": "^4.17.7",
"@balena/odata-parser": "^3.1.0",
"@types/lodash": "^4.17.10",
"@types/memoizee": "^0.4.11",
"@types/string-hash": "^1.1.3",
"lodash": "^4.17.21",
Expand All @@ -27,20 +27,20 @@
},
"devDependencies": {
"@balena/lf-to-abstract-sql": "^5.0.2",
"@balena/lint": "^8.2.7",
"@balena/lint": "^8.2.8",
"@balena/sbvr-parser": "^1.4.6",
"@balena/sbvr-types": "^7.1.3",
"@types/chai": "^4.3.18",
"@types/chai": "^4.3.20",
"@types/chai-things": "0.0.38",
"@types/mocha": "^10.0.7",
"@types/mocha": "^10.0.8",
"chai": "^4.5.0",
"chai-things": "~0.2.0",
"husky": "^9.1.5",
"lint-staged": "^15.2.9",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"mocha": "^10.7.3",
"require-npm4-to-publish": "^1.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
"typescript": "^5.6.2"
},
"mocha": {
"reporter": "spec",
Expand Down
2 changes: 2 additions & 0 deletions src/odata-to-abstract-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,8 @@ export class OData2AbstractSQL {
}
throw new SyntaxError(`${method} is not a number function`);
}
} else if (isBindReference(match)) {
return this.Bind(match);
} else if (optional) {
return;
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ test('/pilot?$expand=licence($top=10)', function (result) {
.find({ 2: 'pilot.licence' })
.find({ 0: 'SelectQuery' })
.value()
.push(['Limit', ['Number', 10]]);
.push(['Limit', ['Bind', 0]]);
it('should select from pilot.*, licence.*', () =>
expect(result)
.to.be.a.query.that.selects([
Expand All @@ -318,7 +318,7 @@ test('/pilot?$expand=licence($skip=10)', function (result) {
.find({ 2: 'pilot.licence' })
.find({ 0: 'SelectQuery' })
.value()
.push(['Offset', ['Number', 10]]);
.push(['Offset', ['Bind', 0]]);
it('should select from pilot.*, licence.*', () =>
expect(result)
.to.be.a.query.that.selects([
Expand Down
16 changes: 8 additions & 8 deletions test/paging.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ test('/pilot?$top=5', (result) =>
expect(result)
.to.be.a.query.that.selects(pilotFields)
.from('pilot')
.limit(['Number', 5])));
.limit(['Bind', 0])));

test('/pilot?$skip=100', (result) =>
it('should select from pilot offset by 100', () =>
expect(result)
.to.be.a.query.that.selects(pilotFields)
.from('pilot')
.offset(['Number', 100])));
.offset(['Bind', 0])));

test('/pilot?$top=5&$skip=100', (result) =>
it('should select from pilot limited by 5 and offset by 100', () =>
expect(result)
.to.be.a.query.that.selects(pilotFields)
.from('pilot')
.limit(['Number', 5])
.offset(['Number', 100])));
.limit(['Bind', 0])
.offset(['Bind', 1])));

const name = 'Peter';
test('/pilot?$top=5&$skip=100', 'PATCH', { name }, (result) =>
Expand All @@ -41,8 +41,8 @@ test('/pilot?$top=5&$skip=100', 'PATCH', { name }, (result) =>
[['Alias', ['ReferencedField', 'pilot', 'id'], '$modifyid']],
],
['From', ['Table', 'pilot']],
['Limit', ['Number', 5]],
['Offset', ['Number', 100]],
['Limit', ['Bind', 0]],
['Offset', ['Bind', 1]],
],
])),
);
Expand All @@ -60,8 +60,8 @@ test('/pilot?$top=5&$skip=100', 'DELETE', (result) =>
[['Alias', ['ReferencedField', 'pilot', 'id'], '$modifyid']],
],
['From', ['Table', 'pilot']],
['Limit', ['Number', 5]],
['Offset', ['Number', 100]],
['Limit', ['Bind', 0]],
['Offset', ['Bind', 1]],
],
])),
);

0 comments on commit 947914b

Please sign in to comment.