Hi there!
I use node 8.1.4 version and express 4.15 on ubuntu 16.04. Node-oracledb support promises and i want write functions with async/await syntaxes, without callbacks (I hope you understand why i do that) .
For example:
let db = require('oracledb');
async function updateCompany(req, res, next) {
try {
const companyName = req.body.companyName;
const company = req.params.company;
const connection = await db.getConnection({user:user, password:password, connectString:string});
const sql = 'update company set cmpname = :companyName where cmpnum = :company';
const result = await connection.execute(sql, {
companyName: companyName,
company: company,
});
await connection.commit();
await connection.close();
res.json({
status: 'OK',
data: result,
});
} catch (err) {
next(err);
}
}
In catch section i handle errors, but can't close connection if my update query is fail.
Are there any best practice for catching errors and closing connection to database in async/await way?
@apechkin Have a look at this post, specifically the employees.js module at the bottom. Also, the parent post for that one provides some background on try...catch...finally.
@dmcghan Awesome articles, it is that i was looking for