Skip to content

Commit 2080a85

Browse files
author
Sylvestre Gug
committed
add pools for oracle
1 parent 7a2b574 commit 2080a85

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/oracle.js

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Transform} from "stream";
44

55
import {badRequest, failedCheck} from "./errors.js";
66
import {validateQueryPayload} from "./validate.js";
7+
import Pools from "./pools.js";
78

89
const READ_ONLY = new Set(["SELECT", "USAGE", "CONNECT"]);
910
export class OracleSingleton {
@@ -217,6 +218,23 @@ export async function check(req, res, pool) {
217218
}
218219
}
219220

221+
export const pools = new Pools(async (credentials) => {
222+
const oracledb = await OracleSingleton.getInstance();
223+
credentials.connectionString = decodeURI(credentials.connectionString);
224+
const pool = await oracledb.createPool(credentials);
225+
226+
Object.defineProperty(pool, "end", {
227+
value() {
228+
// We must ensure there is no query still running before we close the pool.
229+
if (this._connectionsOut === 0) {
230+
this.close();
231+
}
232+
},
233+
});
234+
235+
return pool;
236+
});
237+
220238
export default async ({url, username, password}) => {
221239
OracleSingleton.initialize();
222240
// We do not want to import the oracledb library until we are sure that the user is looking to use Oracle.

0 commit comments

Comments
 (0)