Skip to content

Commit

Permalink
perf: optimize session variables in HANA (#339)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Vogel <31311694+johannes-vogel@users.noreply.github.com>
  • Loading branch information
BobdenOs and johannes-vogel authored Nov 10, 2023
1 parent 4c948fe commit 4240c58
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
7 changes: 1 addition & 6 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ class HANAService extends SQLService {
}

async set(variables) {
const columns = Object.keys(variables).map(
k => `SET '${k.replace(/'/g, "''")}'='${(variables[k] + '').replace(/'/g, "''")}';`,
)
const sql = `DO BEGIN ${columns.join('')} END;`

await this.dbc.exec(sql)
this.dbc.set(variables)
}

async onSELECT({ query, data }) {
Expand Down
5 changes: 5 additions & 0 deletions hana/lib/drivers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class HANADriver {
return prom(this._native, 'exec')(sql)
}

set(variables) {
variables
throw new Error('Implementation missing')
}

/**
* Commits the current transaction
*/
Expand Down
4 changes: 4 additions & 0 deletions hana/lib/drivers/hana-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class HANAClientDriver extends driver {
this._native.setAutoCommit(false)
}

set(variables) {
Object.keys(variables).forEach(k => this._native.setClientInfo(k, variables[k]))
}

async prepare(sql) {
const ret = await super.prepare(sql)
ret.stream = async (values, one) => {
Expand Down
5 changes: 5 additions & 0 deletions hana/lib/drivers/hdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class HDBDriver extends driver {
this.connected = false
}

set(variables) {
const clientInfo = this._native._connection.getClientInfo()
Object.keys(variables).forEach(k => clientInfo.setProperty(k, variables[k]))
}

async prepare(sql) {
const ret = await super.prepare(sql)
ret.stream = async (values, one) => {
Expand Down

0 comments on commit 4240c58

Please sign in to comment.