Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should export conn property #101

Merged
merged 1 commit into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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