loopbackio / loopbackio/loopback-connector-db2

How using query timeout for queries in loopback using DB2 database?

Open
#157 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
JavaScript
Stars
17
Forks
15
PR merge metrics
No merged PRs in 30d

Description

When I use the ibmdb I can configure the query timeout in the statement.

How to do this using the Loopback Model? It's possible?

Example using only IBMDB

```javascript
const ibmdb = require("ibm_db");
const SQL_ATTR_QUERY_TIMEOUT = ibmdb.SQL_ATTR_QUERY_TIMEOUT;
const DB2_QUERY_TIMEOUT = 3; // 3 seconds

const init = async () => {
let DB_CONNECTION = process.env.DB_CONNECTION || 'DATABASE=testdb;HOSTNAME=localhost;PORT=50000;PROTOCOL=TCPIP;UID=DB_USERNAME;PWD=DB_PASSWORD';
let connection = ibmdb.openSync(DB_CONNECTION);
let sql = "update SCHEMA.TABLE set COLUMN1 = 'VALUE' where ID = 1";
let stmt = await prepareStatement(connection, sql);
executeStatement(stmt);
}

const prepareStatement = (conn, sql) => {
return new Promise((resolve, reject) => {
conn.prepare(sql, (err, stmt) => {
if(err) reject(err);
else resolve(stmt);
})
});
}

const executeStatement = (statement, values) => {
statement.setAttr(SQL_ATTR_QUERY_TIMEOUT, DB2_QUERY_TIMEOUT, (err, result) => {
statement.execute(values, function (err, result) {
// return
});
});
}

init();
```

Example using Lookback Model

```javascript
let DataSource = require('loopback-datasource-juggler').DataSource;
let connectorDB2 = require('loopback-connector-db2');

const configDB2 = () => ({
connector: "db2", username: "user", password: "password", hostname: "localhost", port: "50000", database: "DATABASE", schema: "SCHEMA", maxPoolSize: 10, minPoolSize: 5, connectionTimeout: 10
})
let connection = new DataSource(connectorDB2, configDB2());
const schema = { id:{ }, description:{ }};

let Model = connection.define('TABLENAME', schema);
Model.update({id: 1}, {description: 'new value'}); -- how configure query timeout ?
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the LoopBack Model.update example and trace how loopback-connector-db2 executes statements through ibm_db. Check whether the connector exposes statement attributes such as SQL_ATTR_QUERY_TIMEOUT; done means establishing a documented, tested way to configure the timeout for model queries.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.