Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow SELECT.join queries again with full infer call #469

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions db-service/lib/SQLService.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class SQLService extends DatabaseService {
* @type {Handler}
*/
async onSELECT({ query, data }) {
if (!query.target) {
try { this.infer(query) } catch (e) { /**/ }
}
if (query.target && !query.target._unresolved) {
// Will return multiple rows with objects inside
query.SELECT.expand = 'root'
Expand Down
45 changes: 24 additions & 21 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class HANAService extends SQLService {

async onSELECT(req) {
const { query, data } = req
if (!query.target) {
try { this.infer(query) } catch (e) { /**/ }
}
if (!query.target || query.target._unresolved) {
return super.onSELECT(req)
}
Expand All @@ -125,16 +128,16 @@ class HANAService extends SQLService {

async onINSERT({ query, data }) {
try {
const { sql, entries, cqn } = this.cqn2sql(query, data)
if (!sql) return // Do nothing when there is nothing to be done
const ps = await this.prepare(sql)
// HANA driver supports batch execution
const results = await (entries
? HANAVERSION <= 2
? entries.reduce((l, c) => l.then(() => ps.run(c)), Promise.resolve(0))
: ps.run(entries[0])
: ps.run())
return new this.class.InsertResults(cqn, results)
const { sql, entries, cqn } = this.cqn2sql(query, data)
if (!sql) return // Do nothing when there is nothing to be done
const ps = await this.prepare(sql)
// HANA driver supports batch execution
const results = await (entries
? HANAVERSION <= 2
? entries.reduce((l, c) => l.then(() => ps.run(c)), Promise.resolve(0))
: ps.run(entries[0])
: ps.run())
return new this.class.InsertResults(cqn, results)
} catch (err) {
throw _not_unique(err, 'ENTITY_ALREADY_EXISTS')
}
Expand Down Expand Up @@ -812,17 +815,17 @@ class HANAService extends SQLService {
return false
}

list(list) {
const first = list.list[0]
// If the list only contains of lists it is replaced with a json function and a placeholder
if (this.values && first.list && !first.list.find(v => !v.val)) {
const extraction = first.list.map((v, i) => `"${i}" ${this.constructor.InsertTypeMap[typeof v.val]()} PATH '$.V${i}'`)
this.values.push(JSON.stringify(list.list.map(l => l.list.reduce((l, c, i) => { l[`V${i}`] = c.val; return l }, {}))))
return `(SELECT * FROM JSON_TABLE(?, '$' COLUMNS(${extraction})))`
}
// Call super for normal SQL behavior
return super.list(list)
}
list(list) {
const first = list.list[0]
// If the list only contains of lists it is replaced with a json function and a placeholder
if (this.values && first.list && !first.list.find(v => !v.val)) {
const extraction = first.list.map((v, i) => `"${i}" ${this.constructor.InsertTypeMap[typeof v.val]()} PATH '$.V${i}'`)
this.values.push(JSON.stringify(list.list.map(l => l.list.reduce((l, c, i) => { l[`V${i}`] = c.val; return l }, {}))))
return `(SELECT * FROM JSON_TABLE(?, '$' COLUMNS(${extraction})))`
}
// Call super for normal SQL behavior
return super.list(list)
}

quote(s) {
// REVISIT: casing in quotes when reading from entities it uppercase
Expand Down