Skip to content

Commit 80a16e4

Browse files
committed
refactor: rename close to destory
After executing some SQL statements, the connection must be closed
1 parent 977fc26 commit 80a16e4

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

lib/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function createOneClient(config, app) {
2222
app.coreLogger.info(`[egg-oracle] instance[${index}] status OK, currentTime: ${rows[0][0]}`);
2323
});
2424
app.beforeClose(async () => {
25-
await client.close();
25+
await client.destroy();
2626
client = null;
2727
});
2828
return client;

lib/oracle.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ class OracleDB {
2121
* @see {@link https://github.com/OraOpenSource/orawrap}
2222
*/
2323
async getConnection() {
24-
if (this.connection) {
25-
await this.connection.close();
26-
}
27-
this.connection = await this.pool.getConnection();
28-
return this.connection;
24+
return (this.connection = await this.pool.getConnection());
2925
}
3026

3127
/**
28+
* Only select SQL use
3229
* This call executes a SQL or PL/SQL statement. See SQL Execution for examples.
3330
* The statement to be executed may contain IN binds, OUT or IN OUT bind values or variables, which are bound using either an object or an array.
3431
* @param {string} sql SQL Statement.
@@ -37,18 +34,19 @@ class OracleDB {
3734
* @return {ResultObject} result object, containing any fetched rows, the values of any OUT and IN OUT bind variables, and the number of rows affected by the execution of DML statements.
3835
*/
3936
async execute(sql, bindParams = {}, options = {}) {
37+
const connection = this.connection || this.getConnection();
4038
if (typeof sql === 'string' && bindParams instanceof Object) {
4139
try {
42-
return await this.connection.execute(sql, bindParams, options);
40+
return connection.execute(sql, bindParams, options);
4341
} catch (err) {
4442
this.log.error(err.message);
45-
this.getConnection();
43+
await connection.close();
44+
await this.getConnection();
4645
}
4746
}
4847
}
4948

50-
async close() {
51-
await this.connection.close();
49+
async destroy() {
5250
await this.pool.close();
5351
this.connection = null;
5452
this.pool = null;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "egg-oracle",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Oracle database plugin for egg",
55
"eggPlugin": {
66
"name": "oracle"

0 commit comments

Comments
 (0)