@@ -68,6 +68,104 @@ PromiseConnection.prototype.end = function () {
68
68
} ) ;
69
69
} ;
70
70
71
+ PromiseConnection . prototype . beginTransaction = function ( ) {
72
+ var c = this . connection ;
73
+ return new this . Promise ( function ( resolve , reject ) {
74
+ var done = makeDoneCb ( resolve , reject ) ;
75
+ c . beginTransaction ( done ) ;
76
+ } ) ;
77
+ } ;
78
+
79
+ PromiseConnection . prototype . commit = function ( ) {
80
+ var c = this . connection ;
81
+ return new this . Promise ( function ( resolve , reject ) {
82
+ var done = makeDoneCb ( resolve , reject ) ;
83
+ c . commit ( done ) ;
84
+ } ) ;
85
+ } ;
86
+
87
+ PromiseConnection . prototype . rollback = function ( ) {
88
+ var c = this . connection ;
89
+ return new this . Promise ( function ( resolve , reject ) {
90
+ var done = makeDoneCb ( resolve , reject ) ;
91
+ c . rollback ( done ) ;
92
+ } ) ;
93
+ } ;
94
+
95
+ PromiseConnection . prototype . ping = function ( ) {
96
+ var c = this . connection ;
97
+ return new this . Promise ( function ( resolve , reject ) {
98
+ c . ping ( resolve ) ;
99
+ } ) ;
100
+ } ;
101
+
102
+ PromiseConnection . prototype . connect = function ( ) {
103
+ var c = this . connection ;
104
+ return new this . Promise ( function ( resolve , reject ) {
105
+ c . connect ( function ( error , param ) {
106
+ if ( error ) {
107
+ reject ( error ) ;
108
+ } else {
109
+ resolve ( param ) ;
110
+ }
111
+ } ) ;
112
+ } ) ;
113
+ } ;
114
+
115
+ PromiseConnection . prototype . prepare = function ( ) {
116
+ var c = this . connection ;
117
+ return new this . Promise ( function ( resolve , reject ) {
118
+ c . prepare ( function ( error , statement ) {
119
+ if ( error ) {
120
+ reject ( error ) ;
121
+ } else {
122
+ resolve ( statement ) ;
123
+ }
124
+ } ) ;
125
+ } ) ;
126
+ } ;
127
+
128
+ // note: the callback of "changeUser" is not called on success
129
+ // hence there is no possibility to call "resolve"
130
+
131
+ // patching PromiseConnection
132
+ // create facade functions for prototype functions on "Connection" that are not yet
133
+ // implemented with PromiseConnection
134
+
135
+ // proxy synchronous functions only
136
+ ( function ( functionsToWrap ) {
137
+
138
+ for ( var i = 0 ; functionsToWrap && i < functionsToWrap . length ; i ++ ) {
139
+ var func = functionsToWrap [ i ] ;
140
+
141
+ if (
142
+ typeof core . Connection . prototype [ func ] === 'function'
143
+ && PromiseConnection . prototype [ func ] === undefined
144
+ ) {
145
+ PromiseConnection . prototype [ func ] = ( function factory ( funcName ) {
146
+ return function ( ) {
147
+ return core . Connection
148
+ . prototype [ funcName ] . apply ( this . connection , arguments ) ;
149
+ } ;
150
+ } ) ( func ) ;
151
+ }
152
+ }
153
+
154
+ } ) ( [
155
+ // synchronous functions
156
+ 'close' ,
157
+ 'createBinlogStream' ,
158
+ 'destroy' ,
159
+ 'escape' ,
160
+ 'escapeId' ,
161
+ 'format' ,
162
+ 'pause' ,
163
+ 'pipe' ,
164
+ 'resume' ,
165
+ 'unprepare'
166
+ ] ) ;
167
+
168
+
71
169
function createPool ( opts ) {
72
170
var corePool = core . createPool ( opts ) ;
73
171
var Promise = opts . Promise || global . Promise || require ( 'es6-promise' ) ;
0 commit comments