@balena/odata-to-abstract-sql
Advanced tools
Comparing version 6.1.0-build-fisehara-optimize-computed-fields-c49228243e373623eba9f8d63e2f2b391e3517b1-1 to 6.1.0
@@ -7,5 +7,5 @@ # Change Log | ||
## 6.1.0 - 2023-04-27 | ||
## 6.1.0 - 2023-08-16 | ||
* Optimize Duplications of `ComputedField` queries [fisehara] | ||
* Support bind references as boolean types [Pagan Gazzard] | ||
@@ -12,0 +12,0 @@ ## 6.0.1 - 2023-04-27 |
@@ -5,3 +5,3 @@ import * as memoize from 'memoizee'; | ||
export type { ODataBinds, ODataQuery, SupportedMethod }; | ||
type RequiredAbstractSqlModelSubset = Pick<AbstractSqlModel, 'synonyms' | 'relationships' | 'tables' | 'modelName'>; | ||
type RequiredAbstractSqlModelSubset = Pick<AbstractSqlModel, 'synonyms' | 'relationships' | 'tables'>; | ||
type Dictionary<T> = Record<string, T>; | ||
@@ -64,4 +64,2 @@ interface LegacyDefinition { | ||
private checkAlias; | ||
private alreadyComputedFields; | ||
private modelName; | ||
constructor(clientModel: RequiredAbstractSqlModelSubset, methods?: Dictionary<ResourceFunction>, { minimizeAliases }?: { | ||
@@ -68,0 +66,0 @@ minimizeAliases?: boolean | undefined; |
@@ -140,6 +140,4 @@ "use strict"; | ||
this.bindVarsLength = 0; | ||
this.alreadyComputedFields = {}; | ||
const MAX_ALIAS_LENGTH = 63; | ||
const shortAliases = generateShortAliases(clientModel); | ||
this.modelName = clientModel.modelName ?? ''; | ||
this.checkAlias = memoize((alias) => { | ||
@@ -326,5 +324,3 @@ let aliasLength = alias.length; | ||
'Select', | ||
(resource.modifyFields ?? resource.fields) | ||
.filter((field) => field.computed == null) | ||
.map((field) => { | ||
(resource.modifyFields ?? resource.fields).map((field) => { | ||
const alias = field.fieldName; | ||
@@ -667,4 +663,3 @@ const bindVar = bindVars?.find((v) => v[0] === alias); | ||
AliasSelectField(resource, fieldName, computed, alias = fieldName) { | ||
const key = this.modelName + resource.name + fieldName; | ||
if (computed && !this.alreadyComputedFields[key]) { | ||
if (computed) { | ||
if (resource.tableAlias != null && | ||
@@ -674,3 +669,2 @@ resource.tableAlias !== resource.name) { | ||
} | ||
this.alreadyComputedFields[key] = true; | ||
return ['Alias', computed, alias]; | ||
@@ -760,2 +754,5 @@ } | ||
} | ||
else if ((0, exports.isBindReference)(match)) { | ||
return this.Bind(match); | ||
} | ||
else { | ||
@@ -1174,3 +1171,2 @@ try { | ||
this.extraBindVars = []; | ||
this.alreadyComputedFields = {}; | ||
} | ||
@@ -1177,0 +1173,0 @@ putReset() { |
{ | ||
"name": "@balena/odata-to-abstract-sql", | ||
"version": "6.1.0-build-fisehara-optimize-computed-fields-c49228243e373623eba9f8d63e2f2b391e3517b1-1", | ||
"version": "6.1.0", | ||
"description": "A consumer of the OData parser, written in OMeta", | ||
@@ -18,4 +18,4 @@ "main": "out/odata-to-abstract-sql.js", | ||
"dependencies": { | ||
"@balena/abstract-sql-compiler": "^8.4.1", | ||
"@balena/odata-parser": "^3.0.0", | ||
"@balena/abstract-sql-compiler": "8.5.0-build-fisehara-add-model-name-de7bf8742e600a58df7b5a8339b8f8c6b0eab1db-1", | ||
"@types/lodash": "^4.14.194", | ||
@@ -57,4 +57,4 @@ "@types/memoizee": "^0.4.8", | ||
"versionist": { | ||
"publishedAt": "2023-04-27T10:21:57.874Z" | ||
"publishedAt": "2023-08-16T14:48:08.294Z" | ||
} | ||
} |
@@ -86,3 +86,3 @@ import * as _ from 'lodash'; | ||
AbstractSqlModel, | ||
'synonyms' | 'relationships' | 'tables' | 'modelName' | ||
'synonyms' | 'relationships' | 'tables' | ||
>; | ||
@@ -121,4 +121,2 @@ | ||
type AlreadyComputedFieldsLookup = { [key: string]: boolean }; | ||
export type ResourceFunction = ( | ||
@@ -334,4 +332,2 @@ this: OData2AbstractSQL, | ||
private checkAlias: (alias: string) => string; | ||
private alreadyComputedFields: AlreadyComputedFieldsLookup = {}; | ||
private modelName: string; | ||
@@ -345,3 +341,2 @@ constructor( | ||
const shortAliases = generateShortAliases(clientModel); | ||
this.modelName = clientModel.modelName ?? ''; | ||
this.checkAlias = memoize((alias: string) => { | ||
@@ -574,5 +569,4 @@ let aliasLength = alias.length; | ||
'Select', | ||
(resource.modifyFields ?? resource.fields) | ||
.filter((field) => field.computed == null) | ||
.map((field): AliasNode<CastNode> => { | ||
(resource.modifyFields ?? resource.fields).map( | ||
(field): AliasNode<CastNode> => { | ||
const alias = field.fieldName; | ||
@@ -587,3 +581,4 @@ const bindVar = bindVars?.find((v) => v[0] === alias); | ||
return ['Alias', ['Cast', value, field.dataType], alias]; | ||
}), | ||
}, | ||
), | ||
], | ||
@@ -1009,4 +1004,3 @@ ], | ||
| AliasNode<AbstractSqlQuery> { | ||
const key = this.modelName + resource.name + fieldName; | ||
if (computed && !this.alreadyComputedFields[key]) { | ||
if (computed) { | ||
if ( | ||
@@ -1022,3 +1016,2 @@ resource.tableAlias != null && | ||
} | ||
this.alreadyComputedFields[key] = true; | ||
return ['Alias', computed, alias]; | ||
@@ -1127,2 +1120,4 @@ } | ||
} | ||
} else if (isBindReference(match)) { | ||
return this.Bind(match); | ||
} else { | ||
@@ -1651,3 +1646,2 @@ try { | ||
this.extraBindVars = [] as unknown as ODataBinds; | ||
this.alreadyComputedFields = {}; | ||
} | ||
@@ -1654,0 +1648,0 @@ |
@@ -244,2 +244,16 @@ import { expect } from 'chai'; | ||
run(function () { | ||
const odata = operandToOData(true); | ||
const abstractsql = operandToAbstractSQL(true); | ||
return test('/pilot?$filter=' + odata, (result) => | ||
it('should select from pilot where "' + odata + '"', () => { | ||
expect(result) | ||
.to.be.a.query.that.selects(pilotFields) | ||
.from('pilot') | ||
.where(abstractsql); | ||
}), | ||
); | ||
}); | ||
run(function () { | ||
const { odata, abstractsql } = createExpression( | ||
@@ -246,0 +260,0 @@ 'can_fly__plane/id', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6675
1
507079
+ Added@balena/abstract-sql-compiler@8.5.0(transitive)
- Removed@balena/abstract-sql-compiler@8.5.0-build-fisehara-add-model-name-de7bf8742e600a58df7b5a8339b8f8c6b0eab1db-1(transitive)