@cap-js/db-service 1.9.0 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/lib/SQLService.js +2 -2
- package/lib/common/DatabaseService.js +1 -1
- package/lib/common/session-context.js +1 -1
- package/lib/cqn2sql.js +1 -1
- package/lib/cqn4sql.js +14 -12
- package/lib/infer/index.js +1 -1
- package/lib/infer/join-tree.js +5 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@
|
|
|
4
4
|
- The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
5
5
|
- This project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.9.2](https://github.com/cap-js/cds-dbs/compare/db-service-v1.9.1...db-service-v1.9.2) (2024-05-28)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
* do not prepend table alias to session variables ([#656](https://github.com/cap-js/cds-dbs/issues/656)) ([24e8b19](https://github.com/cap-js/cds-dbs/commit/24e8b1995aff3ea971e22849d2f85605f45b0a26))
|
|
13
|
+
|
|
14
|
+
## [1.9.1](https://github.com/cap-js/cds-dbs/compare/db-service-v1.9.0...db-service-v1.9.1) (2024-05-16)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
* dont mistake non-key access with foreign key ([#642](https://github.com/cap-js/cds-dbs/issues/642)) ([2cd2349](https://github.com/cap-js/cds-dbs/commit/2cd234994d6a9e99765e56f7548a42a35279a790))
|
|
20
|
+
|
|
7
21
|
## [1.9.0](https://github.com/cap-js/cds-dbs/compare/db-service-v1.8.0...db-service-v1.9.0) (2024-05-08)
|
|
8
22
|
|
|
9
23
|
|
package/lib/SQLService.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const cds = require('@sap/cds
|
|
1
|
+
const cds = require('@sap/cds'),
|
|
2
2
|
DEBUG = cds.debug('sql|db')
|
|
3
3
|
const { Readable } = require('stream')
|
|
4
4
|
const { resolveView } = require('@sap/cds/libx/_runtime/common/utils/resolveView')
|
|
@@ -135,7 +135,7 @@ class SQLService extends DatabaseService {
|
|
|
135
135
|
if (query._streaming) {
|
|
136
136
|
this._changeToStreams(cqn.SELECT.columns, rows, true, true)
|
|
137
137
|
if (!rows.length) return
|
|
138
|
-
|
|
138
|
+
|
|
139
139
|
const result = rows[0]
|
|
140
140
|
// stream is always on position 0. Further properties like etag are inserted later.
|
|
141
141
|
let [key, val] = Object.entries(result)[0]
|
package/lib/cqn2sql.js
CHANGED
package/lib/cqn4sql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const cds = require('@sap/cds
|
|
3
|
+
const cds = require('@sap/cds')
|
|
4
4
|
const { computeColumnsToBeSearched } = require('./search')
|
|
5
5
|
|
|
6
6
|
const infer = require('./infer')
|
|
@@ -1798,6 +1798,10 @@ function cqn4sql(originalQuery, model) {
|
|
|
1798
1798
|
if (res === '$self')
|
|
1799
1799
|
// next is resolvable in entity
|
|
1800
1800
|
return prev
|
|
1801
|
+
if (res in pseudos.elements) {
|
|
1802
|
+
thing.$refLinks.push({ definition: pseudos.elements[res], target: pseudos })
|
|
1803
|
+
return pseudos.elements[res]
|
|
1804
|
+
}
|
|
1801
1805
|
const definition =
|
|
1802
1806
|
prev?.elements?.[res] || getDefinition(prev?.target)?.elements[res] || pseudos.elements[res]
|
|
1803
1807
|
const target = getParentEntity(definition)
|
|
@@ -1826,8 +1830,9 @@ function cqn4sql(originalQuery, model) {
|
|
|
1826
1830
|
lhs.ref[0] in { $self: true, $projection: true } ? getParentEntity(assocRefLink.definition) : target,
|
|
1827
1831
|
)
|
|
1828
1832
|
else {
|
|
1829
|
-
const lhsLeafArt = lhs.ref && lhs.$refLinks
|
|
1830
|
-
const rhsLeafArt = rhs.ref && rhs.$refLinks
|
|
1833
|
+
const lhsLeafArt = lhs.ref && lhs.$refLinks.at(-1).definition
|
|
1834
|
+
const rhsLeafArt = rhs.ref && rhs.$refLinks.at(-1).definition
|
|
1835
|
+
// compare structures in on-condition
|
|
1831
1836
|
if ((lhsLeafArt?.target && rhsLeafArt?.target) || (lhsLeafArt?.elements && rhsLeafArt?.elements)) {
|
|
1832
1837
|
if (rhs.$refLinks[0].definition !== assocRefLink.definition) {
|
|
1833
1838
|
rhs.ref.unshift(targetSideRefLink.alias)
|
|
@@ -1884,7 +1889,7 @@ function cqn4sql(originalQuery, model) {
|
|
|
1884
1889
|
}
|
|
1885
1890
|
result.splice(i, 3, ...(wrapInXpr ? [asXpr(backlinkOnCondition)] : backlinkOnCondition))
|
|
1886
1891
|
i += wrapInXpr ? 1 : backlinkOnCondition.length // skip inserted tokens
|
|
1887
|
-
} else if (lhs.ref) {
|
|
1892
|
+
} else if (lhs.ref && lhs.$refLinks[0]?.target !== pseudos) {
|
|
1888
1893
|
if (lhs.ref[0] === '$self') {
|
|
1889
1894
|
// $self in ref of length > 1
|
|
1890
1895
|
// if $self is followed by association, the alias of the association must be used
|
|
@@ -1892,11 +1897,7 @@ function cqn4sql(originalQuery, model) {
|
|
|
1892
1897
|
// otherwise $self is replaced by the alias of the entity
|
|
1893
1898
|
else result[i].ref.splice(0, 1, targetSideRefLink.alias)
|
|
1894
1899
|
} else if (lhs.ref.length > 1) {
|
|
1895
|
-
if (
|
|
1896
|
-
!(lhs.ref[0] in pseudos.elements) &&
|
|
1897
|
-
lhs.ref[0] !== assocRefLink.alias &&
|
|
1898
|
-
lhs.ref[0] !== targetSideRefLink.alias
|
|
1899
|
-
) {
|
|
1900
|
+
if (lhs.ref[0] !== assocRefLink.alias && lhs.ref[0] !== targetSideRefLink.alias) {
|
|
1900
1901
|
// we need to find correct table alias for the structured access
|
|
1901
1902
|
const { definition } = lhs.$refLinks[0]
|
|
1902
1903
|
if (definition === assocRefLink.definition) {
|
|
@@ -1910,7 +1911,8 @@ function cqn4sql(originalQuery, model) {
|
|
|
1910
1911
|
result[i].ref = [targetSideRefLink.alias, lhs.ref.join('_')]
|
|
1911
1912
|
}
|
|
1912
1913
|
}
|
|
1913
|
-
} else if (lhs.ref.length === 1)
|
|
1914
|
+
} else if (lhs.ref.length === 1)
|
|
1915
|
+
result[i].ref.unshift(targetSideRefLink.alias)
|
|
1914
1916
|
}
|
|
1915
1917
|
}
|
|
1916
1918
|
return result
|
|
@@ -2175,10 +2177,10 @@ module.exports = Object.assign(cqn4sql, {
|
|
|
2175
2177
|
function calculateElementName(token) {
|
|
2176
2178
|
const nonJoinRelevantAssoc = [...token.$refLinks].findIndex(l => l.definition.isAssociation && l.onlyForeignKeyAccess)
|
|
2177
2179
|
let name
|
|
2178
|
-
if (nonJoinRelevantAssoc)
|
|
2180
|
+
if (nonJoinRelevantAssoc !== -1)
|
|
2179
2181
|
// calculate fk name
|
|
2180
2182
|
name = token.ref.slice(nonJoinRelevantAssoc).join('_')
|
|
2181
|
-
else name = token.$refLinks[token.$refLinks.length - 1].definition
|
|
2183
|
+
else name = getFullName(token.$refLinks[token.$refLinks.length - 1].definition)
|
|
2182
2184
|
return name
|
|
2183
2185
|
}
|
|
2184
2186
|
|
package/lib/infer/index.js
CHANGED
package/lib/infer/join-tree.js
CHANGED
|
@@ -199,7 +199,7 @@ class JoinTree {
|
|
|
199
199
|
}
|
|
200
200
|
const child = new Node($refLink, node, where, args)
|
|
201
201
|
if (child.$refLink.definition.isAssociation) {
|
|
202
|
-
if (child.where || col.inline) {
|
|
202
|
+
if (child.where || child.$refLink.definition.on || col.inline) {
|
|
203
203
|
// filter is always join relevant
|
|
204
204
|
// if the column ends up in an `inline` -> each assoc step is join relevant
|
|
205
205
|
child.$refLink.onlyForeignKeyAccess = false
|
|
@@ -212,9 +212,11 @@ class JoinTree {
|
|
|
212
212
|
const elements =
|
|
213
213
|
node.$refLink?.definition.isAssociation &&
|
|
214
214
|
(node.$refLink.definition.elements || node.$refLink.definition.foreignKeys)
|
|
215
|
-
if (node.$refLink && (!elements || !(child.$refLink.definition.name in elements)))
|
|
216
|
-
// foreign key access
|
|
215
|
+
if (node.$refLink && (!elements || !(child.$refLink.definition.name in elements))) {
|
|
216
|
+
// no foreign key access
|
|
217
217
|
node.$refLink.onlyForeignKeyAccess = false
|
|
218
|
+
col.$refLinks[i - 1] = node.$refLink
|
|
219
|
+
}
|
|
218
220
|
|
|
219
221
|
node.children.set(id, child)
|
|
220
222
|
node = child
|
package/package.json
CHANGED