forked from ali-sdk/ali-rds
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
229 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/**! | ||
* ali-rds - lib/transaction.js | ||
* | ||
* Copyright(c) ali-sdk and other contributors. | ||
* MIT Licensed | ||
* | ||
* Authors: | ||
* fengmk2 <m@fengmk2.com> (http://fengmk2.com) | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
const util = require('util'); | ||
const Operator = require('./operator'); | ||
|
||
module.exports = RDSTransaction; | ||
|
||
function RDSTransaction(conn) { | ||
Operator.call(this); | ||
this.conn = conn; | ||
this.isCommit = false; | ||
this.isRollback = false; | ||
} | ||
util.inherits(RDSTransaction, Operator); | ||
|
||
const proto = RDSTransaction.prototype; | ||
|
||
proto.commit = function* () { | ||
this._check(); | ||
try { | ||
return yield this.conn.commit(); | ||
} finally { | ||
this.conn.release(); | ||
this.conn = null; | ||
} | ||
}; | ||
|
||
proto.rollback = function* () { | ||
this._check(); | ||
try { | ||
return yield this.conn.rollback(); | ||
} finally { | ||
this.conn.release(); | ||
this.conn = null; | ||
} | ||
}; | ||
|
||
proto._query = function* (sql) { | ||
this._check(); | ||
return yield this.conn._query(sql); | ||
}; | ||
|
||
proto._check = function () { | ||
if (!this.conn) { | ||
throw new Error('transaction was commit or rollback'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.