File tree 2 files changed +41
-5
lines changed
2 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ function mixinTransaction(PostgreSQL) {
21
21
debug ( 'Begin a transaction with isolation level: %s' , isolationLevel ) ;
22
22
this . pg . connect ( function ( err , connection , done ) {
23
23
if ( err ) return cb ( err ) ;
24
+ connection . autorelease = done ;
24
25
connection . query ( 'BEGIN TRANSACTION ISOLATION LEVEL ' + isolationLevel ,
25
26
function ( err ) {
26
27
if ( err ) return cb ( err ) ;
@@ -63,15 +64,15 @@ function mixinTransaction(PostgreSQL) {
63
64
} ;
64
65
65
66
PostgreSQL . prototype . releaseConnection = function ( connection , err ) {
66
- if ( typeof connection . release === 'function' ) {
67
- connection . release ( err ) ;
68
- connection . release = null ;
67
+ if ( typeof connection . autorelease === 'function' ) {
68
+ connection . autorelease ( err ) ;
69
+ connection . autorelease = null ;
69
70
} else {
70
71
var pool = this . pg ;
71
72
if ( err ) {
72
- pool . destroy ( connection ) ;
73
+ pool . pool . destroy ( connection ) ;
73
74
} else {
74
- pool . release ( connection ) ;
75
+ pool . pool . release ( connection ) ;
75
76
}
76
77
}
77
78
} ;
Original file line number Diff line number Diff line change @@ -58,6 +58,41 @@ describe('transactions', function() {
58
58
} ;
59
59
}
60
60
61
+ describe ( 'bulk' , function ( ) {
62
+ it ( 'should work with bulk transactions' , function ( done ) {
63
+ var completed = 0 ;
64
+ var concurrent = 20 ;
65
+ for ( var i = 0 ; i <= concurrent ; i ++ ) {
66
+ var post = { title : 'tb' + i , content : 'cb' + i } ;
67
+ var create = createPostInTx ( post ) ;
68
+ Transaction . begin ( db . connector , Transaction . SERIALIZABLE ,
69
+ function ( err , tx ) {
70
+ if ( err ) return done ( err ) ;
71
+ Post . create ( post , { transaction : tx } ,
72
+ function ( err , p ) {
73
+ if ( err ) {
74
+ done ( err ) ;
75
+ } else {
76
+ tx . commit ( function ( err ) {
77
+ if ( err ) {
78
+ done ( err ) ;
79
+ }
80
+ completed ++ ;
81
+ checkResults ( ) ;
82
+ } ) ;
83
+ }
84
+ } ) ;
85
+ } ) ;
86
+ }
87
+
88
+ function checkResults ( ) {
89
+ if ( completed === concurrent ) {
90
+ done ( ) ;
91
+ }
92
+ }
93
+ } ) ;
94
+ } ) ;
95
+
61
96
describe ( 'commit' , function ( ) {
62
97
var post = { title : 't1' , content : 'c1' } ;
63
98
before ( createPostInTx ( post ) ) ;
You can’t perform that action at this time.
0 commit comments