mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Add event-emitters back
This commit is contained in:
parent
0ce8a6c675
commit
76c1000567
@ -374,7 +374,6 @@ Client.prototype.query = function (config, values, callback) {
|
||||
}
|
||||
} else {
|
||||
query = new Query(config, values, callback)
|
||||
query._deprecateListeners()
|
||||
result = query
|
||||
}
|
||||
|
||||
|
||||
@ -131,14 +131,9 @@ Client.prototype.query = function(config, values, callback) {
|
||||
}
|
||||
|
||||
var query = new NativeQuery(config, values, callback);
|
||||
var result = query.callback ? query : new global.Promise(function(resolve, reject) {
|
||||
query.on('end', resolve);
|
||||
query.on('error', reject);
|
||||
});
|
||||
|
||||
this._queryQueue.push(query);
|
||||
this._pulseQueryQueue();
|
||||
return result;
|
||||
return query;
|
||||
};
|
||||
|
||||
//disconnect from the backend server
|
||||
|
||||
@ -67,6 +67,23 @@ NativeQuery.prototype.handleError = function(err) {
|
||||
self.state = 'error';
|
||||
};
|
||||
|
||||
NativeQuery.prototype.then = function(onSuccess, onFailure) {
|
||||
return this._getPromise().then(onSuccess, onFailure);
|
||||
};
|
||||
|
||||
NativeQuery.prototype.catch = function(callback) {
|
||||
return this._getPromise().catch(callback);
|
||||
};
|
||||
|
||||
NativeQuery.prototype._getPromise = function() {
|
||||
if (this._promise) return this._promise;
|
||||
this._promise = new Promise(function(resolve, reject) {
|
||||
this.once('end', resolve);
|
||||
this.once('error', reject);
|
||||
}.bind(this));
|
||||
return this._promise;
|
||||
};
|
||||
|
||||
NativeQuery.prototype.submit = function(client) {
|
||||
this.state = 'running';
|
||||
var self = this;
|
||||
|
||||
@ -70,9 +70,6 @@ Query.prototype._getPromise = function() {
|
||||
return this._promise;
|
||||
};
|
||||
|
||||
Query.prototype._deprecateListeners = function() {
|
||||
}
|
||||
|
||||
//associates row metadata from the supplied
|
||||
//message with this query object
|
||||
//metadata used when parsing row results
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user