Skip to content

Commit

Permalink
Merge branch 'main' into perf/cqn2sql-late-expand
Browse files Browse the repository at this point in the history
  • Loading branch information
BobdenOs authored May 29, 2024
2 parents 599d4f9 + 7bc9972 commit 510d005
Show file tree
Hide file tree
Showing 135 changed files with 3,450 additions and 1,131 deletions.
27 changes: 0 additions & 27 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/hana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ concurrency:
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 20
name: HANA Node.js ${{ matrix.node }}

strategy:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ concurrency:
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
name: Node.js ${{ matrix.node }}

strategy:
Expand Down
8 changes: 4 additions & 4 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"db-service": "1.6.4",
"sqlite": "1.5.1",
"postgres": "1.5.1",
"hana": "0.0.6"
"db-service": "1.10.0",
"sqlite": "1.7.1",
"postgres": "1.9.0",
"hana": "0.5.0"
}
85 changes: 85 additions & 0 deletions db-service/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,91 @@
- The format is based on [Keep a Changelog](http://keepachangelog.com/).
- This project adheres to [Semantic Versioning](http://semver.org/).

## [1.10.0](https://github.com/cap-js/cds-dbs/compare/db-service-v1.9.2...db-service-v1.10.0) (2024-05-29)


### Added

* Add simple queries feature flag ([#660](https://github.com/cap-js/cds-dbs/issues/660)) ([3335202](https://github.com/cap-js/cds-dbs/commit/33352024201a96cc6bdfa30a0fe3fff4227dee10))

## [1.9.2](https://github.com/cap-js/cds-dbs/compare/db-service-v1.9.1...db-service-v1.9.2) (2024-05-28)


### Fixed

* 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))

## [1.9.1](https://github.com/cap-js/cds-dbs/compare/db-service-v1.9.0...db-service-v1.9.1) (2024-05-16)


### Fixed

* 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))

## [1.9.0](https://github.com/cap-js/cds-dbs/compare/db-service-v1.8.0...db-service-v1.9.0) (2024-05-08)


### Added

* Add missing `func` cqn structures ([#629](https://github.com/cap-js/cds-dbs/issues/629)) ([9d7539a](https://github.com/cap-js/cds-dbs/commit/9d7539ab0fc7e70a6a00c0bd9cb4b3e362976e16))


### Fixed

* **`order by`:** reject non-fk traversals of own columns in order by ([#599](https://github.com/cap-js/cds-dbs/issues/599)) ([3288d63](https://github.com/cap-js/cds-dbs/commit/3288d63f0ee6a96580a3b2138ecb24a944371cf1))
* Align all quote functions with @sap/cds-compiler ([#619](https://github.com/cap-js/cds-dbs/issues/619)) ([42e9828](https://github.com/cap-js/cds-dbs/commit/42e9828baf11ec55281ea634ce56ce93e6741b91))
* assign artificial alias if selecting from anonymous subquery ([#608](https://github.com/cap-js/cds-dbs/issues/608)) ([e1a7711](https://github.com/cap-js/cds-dbs/commit/e1a77119f0a5241cfe4f50a37a473f2325ba5bde))
* avoid spread operator ([#630](https://github.com/cap-js/cds-dbs/issues/630)) ([a39fb65](https://github.com/cap-js/cds-dbs/commit/a39fb65f9419fe60e0324741039d004b40082903))
* flat update with arbitrary where clauses ([#598](https://github.com/cap-js/cds-dbs/issues/598)) ([f108798](https://github.com/cap-js/cds-dbs/commit/f108798c6c8035f9cdd0b9c6b8f334f1454c2faa))
* improved `=` and `!=` with val `null` ([#626](https://github.com/cap-js/cds-dbs/issues/626)) ([cbcfe3b](https://github.com/cap-js/cds-dbs/commit/cbcfe3b15e8ebcf7e844dc5406e4bc228d4c94c9))
* Improved placeholders and limit clause ([#567](https://github.com/cap-js/cds-dbs/issues/567)) ([d5d5dbb](https://github.com/cap-js/cds-dbs/commit/d5d5dbb7219bcef6134440715cf756fdd439f076))
* multiple result responses ([#602](https://github.com/cap-js/cds-dbs/issues/602)) ([bf0bed4](https://github.com/cap-js/cds-dbs/commit/bf0bed4549fe816e35481b0c9a7547a522a5a593))
* only consider persisted columns for simple operations ([#592](https://github.com/cap-js/cds-dbs/issues/592)) ([6e31bda](https://github.com/cap-js/cds-dbs/commit/6e31bda1bb15b1770b75c8971773806a26f7d452))


### Changed

* require `>= sap/cds@7.9.0` ([#627](https://github.com/cap-js/cds-dbs/issues/627)) ([f4d09e2](https://github.com/cap-js/cds-dbs/commit/f4d09e27c3b07dd88925e196aefc1087d8357f7a))

## [1.8.0](https://github.com/cap-js/cds-dbs/compare/db-service-v1.7.0...db-service-v1.8.0) (2024-04-12)


### Added

* Odata built-in query functions ([#558](https://github.com/cap-js/cds-dbs/issues/558)) ([6e63367](https://github.com/cap-js/cds-dbs/commit/6e6336757129c4a9dac56f93fd768bb41d071c46))
* support HANA stored procedures ([#542](https://github.com/cap-js/cds-dbs/issues/542)) ([52a00a0](https://github.com/cap-js/cds-dbs/commit/52a00a0d642ba3c58dcad97b3ea1456f1bf3b04a))


### Fixed

* **`expand`:** Only accept on structures, assocs or table aliases ([#551](https://github.com/cap-js/cds-dbs/issues/551)) ([3248512](https://github.com/cap-js/cds-dbs/commit/32485129147cd1b376f1d2faf2ea7c7232ba3794))
* **`order by`:** for localized sorting, prepend table alias ([#546](https://github.com/cap-js/cds-dbs/issues/546)) ([a273a92](https://github.com/cap-js/cds-dbs/commit/a273a9278b2551ed3381795effe28cf8de41b1bd))
* etag with stream_compat ([#562](https://github.com/cap-js/cds-dbs/issues/562)) ([b0a3a41](https://github.com/cap-js/cds-dbs/commit/b0a3a418fbcff7eb7e7b8fa4ff031e1c0c0faac4))
* exclude `cds.LargeBinary` from wildcard expansion ([#577](https://github.com/cap-js/cds-dbs/issues/577)) ([6661d63](https://github.com/cap-js/cds-dbs/commit/6661d635b2895a13d47e42495acf6fbd7247c535))
* Reduce insert queries for deep update ([#568](https://github.com/cap-js/cds-dbs/issues/568)) ([55e5114](https://github.com/cap-js/cds-dbs/commit/55e511471743c0445d41e8297f5530abe167a270))
* Reduced count query complexity when possible ([#553](https://github.com/cap-js/cds-dbs/issues/553)) ([3331f02](https://github.com/cap-js/cds-dbs/commit/3331f0224f02bd2e6cc9c6d2cd5f1c37a36ec8dd))

## [1.7.0](https://github.com/cap-js/cds-dbs/compare/db-service-v1.6.4...db-service-v1.7.0) (2024-03-22)


### Added

* also support lowercase matchespattern function ([#528](https://github.com/cap-js/cds-dbs/issues/528)) ([6ea574e](https://github.com/cap-js/cds-dbs/commit/6ea574ee67ef5e42e4f8ccbe4fe91b46097de129))
* forUpdate and forShareLock ([#148](https://github.com/cap-js/cds-dbs/issues/148)) ([99a1170](https://github.com/cap-js/cds-dbs/commit/99a1170e61de4fd0c505834c25a9c03fc34da85b))
* **hana:** drop prepared statements after end of transaction ([#537](https://github.com/cap-js/cds-dbs/issues/537)) ([b1f864e](https://github.com/cap-js/cds-dbs/commit/b1f864e0a3a0e5efacd803d3709379cab76d61cc))
* **hana:** Add views with parameters support ([#488](https://github.com/cap-js/cds-dbs/issues/488)) ([3790ec0](https://github.com/cap-js/cds-dbs/commit/3790ec0178aab2cdb429272bb3e813b13441785c))
* **orderby:** allow to disable collations with [@cds](https://github.com/cds).collate: false ([#492](https://github.com/cap-js/cds-dbs/issues/492)) ([820f971](https://github.com/cap-js/cds-dbs/commit/820f971e1ad21fa8f8ca289c1e29b373365df484))


### Fixed

* **cqn2sql:** Smart quoting of columns inside UPSERT rows ([#519](https://github.com/cap-js/cds-dbs/issues/519)) ([78fe10b](https://github.com/cap-js/cds-dbs/commit/78fe10b1df3691614dc77b1d4f82df10a1d641d3))
* Getting rid of quirks mode ([#514](https://github.com/cap-js/cds-dbs/issues/514)) ([c9aa6e8](https://github.com/cap-js/cds-dbs/commit/c9aa6e835761ace38447f37cad6a5f39cb0b910c))
* issue with reused select cqns ([#505](https://github.com/cap-js/cds-dbs/issues/505)) ([916d175](https://github.com/cap-js/cds-dbs/commit/916d1756422f0caf02c323052f2addafed39182a))
* joins without columns are rejected ([#535](https://github.com/cap-js/cds-dbs/issues/535)) ([eb9beda](https://github.com/cap-js/cds-dbs/commit/eb9beda728de60081d7afbfcd49305eeb241f3fb))
* **search:** dont search non string aggregations ([#527](https://github.com/cap-js/cds-dbs/issues/527)) ([c87900c](https://github.com/cap-js/cds-dbs/commit/c87900cb157041a6ff76c45192c1d33180840d0f))
* **search:** search on aggregated results in HAVING clause ([#524](https://github.com/cap-js/cds-dbs/issues/524)) ([61d348e](https://github.com/cap-js/cds-dbs/commit/61d348ebc2528b7f1c6da8c78a7455a438e1b7cf))

## [1.6.4](https://github.com/cap-js/cds-dbs/compare/db-service-v1.6.3...db-service-v1.6.4) (2024-02-28)


Expand Down
28 changes: 21 additions & 7 deletions db-service/lib/SQLService.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cds = require('@sap/cds/lib'),
const cds = require('@sap/cds'),
DEBUG = cds.debug('sql|db')
const { Readable } = require('stream')
const { resolveView } = require('@sap/cds/libx/_runtime/common/utils/resolveView')
Expand Down Expand Up @@ -134,7 +134,15 @@ class SQLService extends DatabaseService {
if (cds.env.features.stream_compat) {
if (query._streaming) {
this._changeToStreams(cqn.SELECT.columns, rows, true, true)
return rows.length ? { value: Object.values(rows[0])[0] } : undefined
if (!rows.length) return

const result = rows[0]
// stream is always on position 0. Further properties like etag are inserted later.
let [key, val] = Object.entries(result)[0]
result.value = val
delete result[key]

return result
}
} else {
this._changeToStreams(cqn.SELECT.columns, rows, query.SELECT.one, false)
Expand Down Expand Up @@ -265,7 +273,7 @@ class SQLService extends DatabaseService {
* @param {string} sql
*/
hasResults(sql) {
return /^(SELECT|WITH|CALL|PRAGMA table_info)/i.test(sql)
return /^\s*(SELECT|WITH|CALL|PRAGMA table_info)/i.test(sql)
}

/**
Expand All @@ -281,17 +289,23 @@ class SQLService extends DatabaseService {
const [max, offset = 0] = one ? [1] : _ ? [_.rows?.val, _.offset?.val] : []
if (max === undefined || (n < max && (n || !offset))) return n + offset
}
// REVISIT: made uppercase count because of HANA reserved word quoting
const cq = SELECT.one([{ func: 'count', as: 'COUNT' }]).from(

// Keep original query columns when potentially used insde conditions
const { having, groupBy } = query.SELECT
const columns = (having?.length || groupBy?.length)
? query.SELECT.columns.filter(c => !c.expand)
: [{ val: 1 }]
const cq = SELECT.one([{ func: 'count' }]).from(
cds.ql.clone(query, {
columns,
localized: false,
expand: false,
limit: undefined,
orderBy: undefined,
}),
)
const { count, COUNT } = await this.onSELECT({ query: cq })
return count ?? COUNT
const { count } = await this.onSELECT({ query: cq })
return count
}

/**
Expand Down
2 changes: 1 addition & 1 deletion db-service/lib/common/DatabaseService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const SessionContext = require('./session-context')
const ConnectionPool = require('./generic-pool')
const infer = require('../infer')
const cds = require('@sap/cds/lib')
const cds = require('@sap/cds')

/** @typedef {unknown} DatabaseDriver */

Expand Down
2 changes: 1 addition & 1 deletion db-service/lib/common/session-context.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cds = require('@sap/cds/lib')
const cds = require('@sap/cds')

class SessionContext {
constructor(ctx) {
Expand Down
36 changes: 18 additions & 18 deletions db-service/lib/cql-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ const StandardFunctions = {
* @returns {string}
*/
matchesPattern: (x, y) => `(${x} regexp ${y})`,
/**
* Generates SQL statement that matches the given string against a regular expression
* @param {string} x
* @param {string} y
* @returns {string}
*/
matchespattern: (x, y) => `(${x} regexp ${y})`,
/**
* Generates SQL statement that produces the lower case value of a given string
* @param {string} x
Expand Down Expand Up @@ -145,6 +152,13 @@ const StandardFunctions = {
current_time: p => (p ? `current_time(${p})` : 'current_time'),
current_timestamp: p => (p ? `current_timestamp(${p})` : 'current_timestamp'),

/**
* Generates SQL statement that produces current point in time (date and time with time zone)
* @returns {string}
*/
now: function() {
return this.session_context({val: '$now'})
},
/**
* Generates SQL statement that produces the year of a given timestamp
* @param {string} x
Expand Down Expand Up @@ -182,38 +196,24 @@ const StandardFunctions = {
* /
second: x => `cast( strftime('%S',${x}) as Integer )`,
// REVISIT: make precision configurable
/**
* Generates SQL statement that produces the fractional seconds of a given timestamp
* @param {string} x
* @returns {string}
*/
fractionalseconds: x => `cast( strftime('%f0000',${x}) as Integer )`,
fractionalseconds: x => `cast( substr( strftime('%f', ${x}), length(strftime('%f', ${x})) - 3) as REAL)`,

/**
* maximum date time value
* @returns {string}
*/
maxdatetime: () => '9999-12-31 23:59:59.999',
maxdatetime: () => "'9999-12-31T23:59:59.999Z'",
/**
* minimum date time value
* @returns {string}
*/
mindatetime: () => '0001-01-01 00:00:00.000',

// odata spec defines the date time offset type as a normal ISO time stamp
// Where the timezone can either be 'Z' (for UTC) or [+|-]xx:xx for the time offset
// sqlite understands this so by splitting the timezone from the actual date
// prefixing it with 1970 it allows sqlite to give back the number of seconds
// which can be divided by 60 back to minutes
/**
* Generates SQL statement that produces the offset in minutes of a given date time offset string
* @param {string} x
* @returns {string}
*/
totaloffsetminutes: x => `case
when substr(${x}, length(${x})) = 'z' then 0
else strftime('%s', '1970-01-01T00:00:00' || substr(${x}, length(${x}) - 5)) / 60
end`,
mindatetime: () => "'0001-01-01T00:00:00.000Z'",

// odata spec defines the value format for totalseconds as a duration like: P12DT23H59M59.999999999999S
// P -> duration indicator
Expand Down
Loading

0 comments on commit 510d005

Please sign in to comment.