-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
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
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
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 ?