@balena/abstract-sql-compiler
Advanced tools
Comparing version
@@ -984,8 +984,3 @@ "use strict"; | ||
case 'UnionQuery': | ||
values = [ | ||
[ | ||
'Values', | ||
typeRules[valuesType](valuesRest), | ||
], | ||
]; | ||
values = [['Values', typeRules[valuesType](valuesRest)]]; | ||
break; | ||
@@ -992,0 +987,0 @@ default: |
@@ -760,3 +760,3 @@ "use strict"; | ||
const typeName = args[1]; | ||
if (!sbvr_types_1.default[typeName] || !sbvr_types_1.default[typeName].types[engine]) { | ||
if (!sbvr_types_1.default[typeName]?.types[engine]) { | ||
throw new SyntaxError(`Invalid cast type: ${typeName}`); | ||
@@ -763,0 +763,0 @@ } |
{ | ||
"name": "@balena/abstract-sql-compiler", | ||
"version": "9.2.1-build-renovate-major-9--balenasbvr-types-e797282c058826c1e4ebb4720dc2478350daae4d-1", | ||
"version": "9.2.1-build-update-dependencies-8b6f93b0b1649d5a0c4d48cbd29dae2f4121ac99-1", | ||
"description": "A translator for abstract sql into sql.", | ||
@@ -19,23 +19,23 @@ "main": "out/AbstractSQLCompiler.js", | ||
"dependencies": { | ||
"@balena/sbvr-types": "^9.0.0", | ||
"@balena/sbvr-types": "^9.0.2, ^8.0.0, 7.0.1", | ||
"lodash": "^4.17.21" | ||
}, | ||
"devDependencies": { | ||
"@balena/lf-to-abstract-sql": "^5.0.0", | ||
"@balena/lint": "^8.0.0", | ||
"@balena/odata-parser": "^3.0.0", | ||
"@balena/odata-to-abstract-sql": "^6.0.1", | ||
"@balena/sbvr-parser": "^1.4.3", | ||
"@balena/lf-to-abstract-sql": "^5.0.2", | ||
"@balena/lint": "^8.2.8", | ||
"@balena/odata-parser": "^3.1.0", | ||
"@balena/odata-to-abstract-sql": "^6.4.0", | ||
"@balena/sbvr-parser": "^1.4.6", | ||
"@types/chai": "^4.3.4", | ||
"@types/common-tags": "^1.8.1", | ||
"@types/lodash": "^4.14.192", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^20.0.0", | ||
"@types/common-tags": "^1.8.4", | ||
"@types/lodash": "^4.17.10", | ||
"@types/mocha": "^10.0.8", | ||
"@types/node": "^22.7.4", | ||
"chai": "^4.3.7", | ||
"common-tags": "^1.8.2", | ||
"husky": "^9.0.0", | ||
"lint-staged": "^15.0.0", | ||
"mocha": "^10.2.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.4.3" | ||
"husky": "^9.1.6", | ||
"lint-staged": "^15.2.10", | ||
"mocha": "^10.7.3", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.6.2" | ||
}, | ||
@@ -65,4 +65,4 @@ "lint-staged": { | ||
"versionist": { | ||
"publishedAt": "2024-08-08T08:45:00.168Z" | ||
"publishedAt": "2024-10-04T14:50:20.709Z" | ||
} | ||
} |
@@ -326,3 +326,3 @@ import * as _ from 'lodash'; | ||
const AnyNotNullValue = (args: any): boolean => { | ||
return args != null && (args as any) !== 'Null' && args[0] !== 'Null'; | ||
return args != null && args !== 'Null' && args[0] !== 'Null'; | ||
}; | ||
@@ -607,11 +607,3 @@ | ||
case 'CrossJoin': | ||
tables.push( | ||
typeRules[type](rest) as | ||
| FromNode | ||
| InnerJoinNode | ||
| LeftJoinNode | ||
| RightJoinNode | ||
| FullJoinNode | ||
| CrossJoinNode, | ||
); | ||
tables.push(typeRules[type](rest)); | ||
break; | ||
@@ -1380,10 +1372,3 @@ case 'Where': | ||
case 'UnionQuery': | ||
values = [ | ||
[ | ||
'Values', | ||
typeRules[valuesType](valuesRest) as | ||
| SelectQueryNode | ||
| UnionQueryNode, | ||
], | ||
]; | ||
values = [['Values', typeRules[valuesType](valuesRest)]]; | ||
break; | ||
@@ -1390,0 +1375,0 @@ default: |
@@ -41,3 +41,3 @@ import * as _ from 'lodash'; | ||
let engine: Engines = Engines.postgres; | ||
let noBinds: boolean = false; | ||
let noBinds = false; | ||
@@ -673,3 +673,3 @@ export const comparisons = { | ||
const joins: string[] = []; | ||
let select: string = ''; | ||
let select = ''; | ||
const groups = { | ||
@@ -874,3 +874,3 @@ Where: '', | ||
const typeName = args[1] as keyof typeof sbvrTypes; | ||
if (!sbvrTypes[typeName] || !sbvrTypes[typeName].types[engine]) { | ||
if (!sbvrTypes[typeName]?.types[engine]) { | ||
throw new SyntaxError(`Invalid cast type: ${typeName}`); | ||
@@ -1457,3 +1457,3 @@ } | ||
let values: string[] = []; | ||
let where: string = ''; | ||
let where = ''; | ||
for (const arg of args) { | ||
@@ -1517,3 +1517,3 @@ if (!isAbstractSqlQuery(arg)) { | ||
const tables: string[] = []; | ||
let where: string = ''; | ||
let where = ''; | ||
for (const arg of args) { | ||
@@ -1520,0 +1520,0 @@ if (!isAbstractSqlQuery(arg)) { |
@@ -47,3 +47,3 @@ export const enum Engines { | ||
abstractSqlModel: AbstractSqlModel, | ||
createCheckConstraints: boolean = true, | ||
createCheckConstraints = true, | ||
): AbstractSqlModel => { | ||
@@ -130,3 +130,3 @@ abstractSqlModel.rules = abstractSqlModel.rules | ||
table.checks ??= []; | ||
table.checks!.push({ | ||
table.checks.push({ | ||
description: ruleSE, | ||
@@ -133,0 +133,0 @@ name: generateRuleSlug(tableName, ruleBody), |
@@ -273,3 +273,3 @@ import * as _ from 'lodash'; | ||
) { | ||
const select = ruleBody[1].find(isSelectNode) as SelectNode; | ||
const select = ruleBody[1].find(isSelectNode)!; | ||
select[1] = []; | ||
@@ -276,0 +276,0 @@ $getRuleReferencedFields(referencedFields, ruleBody[1], IsSafe.Delete); |
@@ -439,3 +439,3 @@ import test from './test'; | ||
WHERE "pilot"."licence" = "pilot.licence"."id" | ||
LIMIT 10 | ||
LIMIT ? | ||
) AS "pilot.licence" | ||
@@ -448,5 +448,5 @@ ) AS "licence", ${remainingPilotFields} | ||
const url = '/pilot?$expand=licence($top=10)'; | ||
test.postgres(url, testFunc(postgresAgg)); | ||
test.mysql.skip(url, testFunc(mysqlAgg)); | ||
test.websql.skip(url, testFunc(websqlAgg)); | ||
test.postgres(url, 'GET', [['Bind', 0]], testFunc(postgresAgg)); | ||
test.mysql.skip(url, 'GET', [['Bind', 0]], testFunc(mysqlAgg)); | ||
test.websql.skip(url, 'GET', [['Bind', 0]], testFunc(websqlAgg)); | ||
})(); | ||
@@ -498,3 +498,3 @@ | ||
WHERE "pilot"."licence" = "pilot.licence"."id" | ||
OFFSET 10 | ||
OFFSET ? | ||
) AS "pilot.licence" | ||
@@ -507,5 +507,5 @@ ) AS "licence", ${remainingPilotFields} | ||
const url = '/pilot?$expand=licence($skip=10)'; | ||
test.postgres(url, testFunc(postgresAgg)); | ||
test.mysql.skip(url, testFunc(mysqlAgg)); | ||
test.websql.skip(url, testFunc(websqlAgg)); | ||
test.postgres(url, 'GET', [['Bind', 0]], testFunc(postgresAgg)); | ||
test.mysql.skip(url, 'GET', [['Bind', 0]], testFunc(mysqlAgg)); | ||
test.websql.skip(url, 'GET', [['Bind', 0]], testFunc(websqlAgg)); | ||
})(); | ||
@@ -512,0 +512,0 @@ |
@@ -72,3 +72,3 @@ /* | ||
_.isDate(operand) || | ||
(typeof operand === 'string' && operand.charAt(0) === "'") | ||
(typeof operand === 'string' && operand.startsWith("'")) | ||
) { | ||
@@ -99,3 +99,3 @@ return [['Bind', bindNo++]]; | ||
} | ||
if (operand.charAt(0) === "'") { | ||
if (operand.startsWith("'")) { | ||
return '?'; | ||
@@ -641,3 +641,3 @@ } | ||
WHERE "pilot"."id" IN (( | ||
SELECT "pilot"."id" | ||
SELECT "pilot"."id" AS "$modifyid" | ||
FROM "pilot", | ||
@@ -737,3 +737,3 @@ "pilot-can fly-plane" AS "pilot.pilot-can fly-plane", | ||
WHERE "pilot"."id" IN (( | ||
SELECT "pilot"."id" | ||
SELECT "pilot"."id" AS "$modifyid" | ||
FROM "pilot", | ||
@@ -815,3 +815,3 @@ "pilot-can fly-plane" AS "pilot.pilot-can fly-plane", | ||
AND "pilot"."id" IN (( | ||
SELECT "pilot"."id" | ||
SELECT "pilot"."id" AS "$modifyid" | ||
FROM "pilot" | ||
@@ -873,3 +873,3 @@ WHERE ${sql} | ||
AND "pilot"."id" IN (( | ||
SELECT "pilot"."id" | ||
SELECT "pilot"."id" AS "$modifyid" | ||
FROM "pilot" | ||
@@ -876,0 +876,0 @@ WHERE ${sql} |
@@ -5,3 +5,3 @@ import test from './test'; | ||
test('/pilot?$top=5', (result, sqlEquals) => { | ||
test('/pilot?$top=5', 'GET', [['Bind', 0]], (result, sqlEquals) => { | ||
it('should select from pilot limited by 5', () => { | ||
@@ -13,3 +13,3 @@ sqlEquals( | ||
FROM "pilot" | ||
LIMIT 5`, | ||
LIMIT ?`, | ||
); | ||
@@ -19,3 +19,3 @@ }); | ||
test('/pilot?$skip=100', (result, sqlEquals) => { | ||
test('/pilot?$skip=100', 'GET', [['Bind', 0]], (result, sqlEquals) => { | ||
it('should select from pilot offset by 100', () => { | ||
@@ -27,3 +27,3 @@ sqlEquals( | ||
FROM "pilot" | ||
OFFSET 100`, | ||
OFFSET ?`, | ||
); | ||
@@ -33,13 +33,21 @@ }); | ||
test('/pilot?$top=5&$skip=100', (result, sqlEquals) => { | ||
it('should select from pilot limited by 5 and offset by 100', () => { | ||
sqlEquals( | ||
result.query, | ||
`\ | ||
test( | ||
'/pilot?$top=5&$skip=100', | ||
'GET', | ||
[ | ||
['Bind', 0], | ||
['Bind', 1], | ||
], | ||
(result, sqlEquals) => { | ||
it('should select from pilot limited by 5 and offset by 100', () => { | ||
sqlEquals( | ||
result.query, | ||
`\ | ||
SELECT ${pilotFieldsStr} | ||
FROM "pilot" | ||
LIMIT 5 | ||
OFFSET 100`, | ||
); | ||
}); | ||
}); | ||
LIMIT ? | ||
OFFSET ?`, | ||
); | ||
}); | ||
}, | ||
); |
@@ -32,3 +32,3 @@ import * as fs from 'node:fs'; | ||
it('informative - no foreignKey for reference field', async () => { | ||
it('informative - no foreignKey for reference field', () => { | ||
test( | ||
@@ -35,0 +35,0 @@ `\ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
994027
16.71%17920
-0.07%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed