Skip to content
Open
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
26 changes: 18 additions & 8 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ class HANAService extends SQLService {
this.on(['COMMIT'], this.onCOMMIT)
this.on(['ROLLBACK'], this.onROLLBACK)
this.on(['SELECT', 'INSERT', 'UPSERT', 'UPDATE', 'DELETE'], this.onNOTFOUND)

// TODO: remove
this.options._max_statement_count = 10
Comment on lines +40 to +42
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO: remove
this.options._max_statement_count = 10


// destroy connections that have exceeded the max statement count
const { _max_statement_count } = this.options
if (_max_statement_count) {
const { release, destroy } = this
this.release = function () {
if (this.dbc?._native?._statement_count > _max_statement_count) return destroy.call(this)
return release.call(this)
}
}

return super.init()
}

Expand Down Expand Up @@ -1366,19 +1380,15 @@ SELECT ${mixing} FROM JSON_TABLE(SRC.JSON, '$' COLUMNS(${extraction}) ERROR ON E

onCOMMIT() {
DEBUG?.('COMMIT')
this.dbc?.statements?.forEach(stmt => stmt
.then(stmt => stmt.drop())
.catch(() => { })
)
if (!this.options._max_statement_count)
this.dbc?.statements?.forEach(stmt => stmt.then(stmt => stmt.drop()).catch(() => {}))
return this.dbc?.commit()
}

onROLLBACK() {
DEBUG?.('ROLLBACK')
this.dbc?.statements?.forEach(stmt => stmt
.then(stmt => stmt.drop())
.catch(() => { })
)
if (!this.options._max_statement_count)
this.dbc?.statements?.forEach(stmt => stmt.then(stmt => stmt.drop()).catch(() => {}))
return this.dbc?.rollback()
}

Expand Down
2 changes: 2 additions & 0 deletions hana/lib/drivers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class HANADriver {
* @returns {import('@cap-js/db-service/lib/SQLService').PreparedStatement}
*/
async prepare(sql) {
this._native._statement_count ??= 0
const prep = module.exports.prom(
this._native,
'prepare',
)(sql).then(stmt => {
this._native._statement_count++
stmt._parentConnection = this._native
return stmt
})
Expand Down
Loading