Skip to content

Commit

Permalink
fix: should export conn property (ali-sdk#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Dec 22, 2022
1 parent 907a89b commit 37afa42
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release

on:
push:
branches: [ master ]

workflow_dispatch: {}

jobs:
release:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-release.yml@v1
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
with:
checkTest: false
19 changes: 9 additions & 10 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,40 @@ const Operator = require('./operator');
const kWrapToRDS = Symbol('kWrapToRDS');

class RDSConnection extends Operator {
#conn;
constructor(conn) {
super();
this.#conn = conn;
if (!this.#conn[kWrapToRDS]) {
this.conn = conn;
if (!this.conn[kWrapToRDS]) {
[
'query',
'beginTransaction',
'commit',
'rollback',
].forEach(key => {
this.#conn[key] = promisify(this.#conn[key]);
this.conn[key] = promisify(this.conn[key]);
});
this.#conn[kWrapToRDS] = true;
this.conn[kWrapToRDS] = true;
}
}

release() {
return this.#conn.release();
return this.conn.release();
}

async _query(sql) {
return await this.#conn.query(sql);
return await this.conn.query(sql);
}

async beginTransaction() {
return await this.#conn.beginTransaction();
return await this.conn.beginTransaction();
}

async commit() {
return await this.#conn.commit();
return await this.conn.commit();
}

async rollback() {
return await this.#conn.rollback();
return await this.conn.rollback();
}
}

Expand Down
19 changes: 9 additions & 10 deletions lib/transaction.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
const Operator = require('./operator');

class RDSTransaction extends Operator {
#conn;
isCommit = false;
isRollback = false;
constructor(conn) {
super();
this.#conn = conn;
this.conn = conn;
}

async commit() {
this.#check();
try {
return await this.#conn.commit();
return await this.conn.commit();
} finally {
this.isCommit = true;
this.#conn.release();
this.#conn = null;
this.conn.release();
this.conn = null;
}
}

async rollback() {
this.#check();
try {
return await this.#conn.rollback();
return await this.conn.rollback();
} finally {
this.isRollback = true;
this.#conn.release();
this.#conn = null;
this.conn.release();
this.conn = null;
}
}

async _query(sql) {
this.#check();
return await this.#conn._query(sql);
return await this.conn._query(sql);
}

#check() {
if (!this.#conn) {
if (!this.conn) {
throw new Error('transaction was commit or rollback');
}
}
Expand Down

0 comments on commit 37afa42

Please sign in to comment.