So I'm trying to add Oracle DB support in my Node App. I'm using node-oracledb to do this.
As I am also using MSSQL in my app already, I want to implement a 'similar' workflow to use Oracle.
Right now I use a class that implements methods using promises, like this:
class db {
constructor(){
this._pool = null;
}
get_pool(){
//for MSSQL
if (!this._pool) {
this._pool = new mssql.ConnectionPool(sqlDbOptions);
}
//connect pool
if (!this._pool.connected){
return this._pool.connect();
}
else{
return new Promise((resolve, reject) => {
resolve(this._pool);
})
}
}
insert(sql){
return this.get_pool().then((pool) => {...
....
....
}
}
As you can see, calling the insert method gets returns the insert promise after getting the pool from get_pool() (which checks if the pool is connected, and connects it if it isn't).
I tried using the same logic for oracle, from what I'm reading in their docs for promises, using something like this in the get_pool():
if (!this._pool){
this._pool = new oracle.createPool(oracleDbOptions);
}
if (this._pool.connectionsOpen == 0){
return this._pool.getConnection();
}
else{
return new Promise((resolve, reject) => {
resolve(this._pool);
})
}
This isn't working, as for some reason the oracle.createPool(options) also returns a promise, which I noticed takes a lot to resolve (no idea why, as it isn't connecting).
Any idea how to achieve the same behavior as the one I used for MSSQL here?
Thanks!