Skip to content

Commit 1bc1758

Browse files
committed
Remove deprecated methods
1 parent 313c41a commit 1bc1758

40 files changed

+368
-555
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ help:
1717

1818
test: test-unit
1919

20-
test-all: jshint test-missing-native test-unit test-integration test-native test-binary
20+
test-all: jshint test-missing-native test-unit test-integration test-native
2121

2222

2323
update-npm:

lib/index.js

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var ConnectionParameters = require('./connection-parameters');
1515
var poolFactory = require('./pool-factory');
1616

1717
var PG = function(clientConstructor) {
18-
EventEmitter.call(this);
1918
this.defaults = defaults;
2019
this.Client = clientConstructor;
2120
this.Query = this.Client.Query;
@@ -25,74 +24,6 @@ var PG = function(clientConstructor) {
2524
this.types = require('pg-types');
2625
};
2726

28-
util.inherits(PG, EventEmitter);
29-
30-
PG.prototype.end = util.deprecate(function() {
31-
var self = this;
32-
var keys = Object.keys(this._pools);
33-
var count = keys.length;
34-
if(count === 0) {
35-
self.emit('end');
36-
} else {
37-
keys.forEach(function(key) {
38-
var pool = self._pools[key];
39-
delete self._pools[key];
40-
pool.pool.drain(function() {
41-
pool.pool.destroyAllNow(function() {
42-
count--;
43-
if(count === 0) {
44-
self.emit('end');
45-
}
46-
});
47-
});
48-
});
49-
}
50-
},
51-
'pg.end() is deprecated - please construct pools directly via new pg.Pool()');
52-
53-
PG.prototype.connect = util.deprecate(function(config, callback) {
54-
if(typeof config == "function") {
55-
callback = config;
56-
config = null;
57-
}
58-
if (typeof config == 'string') {
59-
config = new ConnectionParameters(config);
60-
}
61-
62-
config = config || {};
63-
64-
//for backwards compatibility
65-
config.max = config.max || config.poolSize || defaults.poolSize;
66-
config.idleTimeoutMillis = config.idleTimeoutMillis || config.poolIdleTimeout || defaults.poolIdleTimeout;
67-
config.log = config.log || config.poolLog || defaults.poolLog;
68-
69-
var poolName = JSON.stringify(config);
70-
this._pools[poolName] = this._pools[poolName] || new this.Pool(config);
71-
var pool = this._pools[poolName];
72-
if(!pool.listeners('error').length) {
73-
//propagate errors up to pg object
74-
pool.on('error', function(e) {
75-
this.emit('error', e, e.client);
76-
}.bind(this));
77-
}
78-
return pool.connect(callback);
79-
},
80-
'pg.connect() is deprecated - please construct pools directly via new pg.Pool()');
81-
82-
// cancel the query running on the given client
83-
PG.prototype.cancel = util.deprecate(function(config, client, query) {
84-
if(client.native) {
85-
return client.cancel(query);
86-
}
87-
var c = config;
88-
//allow for no config to be passed
89-
if(typeof c === 'function') {
90-
c = defaults;
91-
}
92-
var cancellingClient = new this.Client(c);
93-
cancellingClient.cancel(client, query);
94-
}, 'pg.cancel() is deprecated - please create your own client instances to cancel queries');
95-
9627
if(typeof process.env.NODE_PG_FORCE_NATIVE != 'undefined') {
9728
module.exports = new PG(require('./native'));
9829
} else {

lib/native/client.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ Client.prototype.connect = function(cb) {
109109
return result
110110
};
111111

112-
const DeprecatedQuery = require('../utils').deprecateEventEmitter(NativeQuery)
113-
114112
//send a query to the server
115113
//this method is highly overloaded to take
116114
//1) string query, optional array of parameters, optional function callback
@@ -132,10 +130,19 @@ Client.prototype.query = function(config, values, callback) {
132130
return config;
133131
}
134132

135-
var query = new DeprecatedQuery(config, values, callback);
133+
var query = new NativeQuery(config, values, callback);
134+
var result
135+
if (!query.callback) {
136+
let resolve, reject;
137+
result = new Promise((res, rej) => {
138+
resolve = res
139+
reject = rej
140+
})
141+
query.callback = (err, res) => err ? reject(err) : resolve(res)
142+
}
136143
this._queryQueue.push(query);
137144
this._pulseQueryQueue();
138-
return query;
145+
return result;
139146
};
140147

141148
//disconnect from the backend server

lib/query.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,6 @@ Query.prototype.requiresPreparation = function() {
5353
return this.values.length > 0;
5454
};
5555

56-
Query.prototype.then = function(onSuccess, onFailure) {
57-
return this._getPromise().then(onSuccess, onFailure);
58-
};
59-
60-
Query.prototype.catch = function(callback) {
61-
return this._getPromise().catch(callback);
62-
};
63-
64-
Query.prototype._getPromise = function() {
65-
if (this._promise) return this._promise;
66-
this._promise = new Promise(function(resolve, reject) {
67-
this._once('end', resolve);
68-
this._once('error', reject);
69-
}.bind(this));
70-
return this._promise;
71-
};
72-
7356
//associates row metadata from the supplied
7457
//message with this query object
7558
//metadata used when parsing row results

lib/utils.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,29 +138,11 @@ function normalizeQueryConfig (config, values, callback) {
138138
return config;
139139
}
140140

141-
const queryEventEmitterOverloadDeprecationMessage = `
142-
Using the automatically created return value from client.query as an event emitter is deprecated.
143-
Use either the callback or promise interface.
144-
`
145-
146-
const deprecateEventEmitter = function(Emitter) {
147-
const Result = function () {
148-
Emitter.apply(this, arguments)
149-
}
150-
util.inherits(Result, Emitter)
151-
Result.prototype._on = Result.prototype.on
152-
Result.prototype._once = Result.prototype.once
153-
Result.prototype.on = util.deprecate(Result.prototype.on, queryEventEmitterOverloadDeprecationMessage)
154-
Result.prototype.once = util.deprecate(Result.prototype.once, queryEventEmitterOverloadDeprecationMessage)
155-
return Result
156-
}
157-
158141
module.exports = {
159142
prepareValue: function prepareValueWrapper (value) {
160143
//this ensures that extra arguments do not get passed into prepareValue
161144
//by accident, eg: from calling values.map(utils.prepareValue)
162145
return prepareValue(value);
163146
},
164147
normalizeQueryConfig: normalizeQueryConfig,
165-
deprecateEventEmitter: deprecateEventEmitter,
166148
};

test/integration/client/array-tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ var pg = helper.pg;
33

44
var suite = new helper.Suite()
55

6-
pg.connect(assert.calls(function(err, client, release) {
6+
const pool = new pg.Pool()
7+
pool.connect(assert.calls(function(err, client, release) {
78
assert.isNull(err);
89

910
suite.test('nulls', function(done) {
@@ -33,7 +34,7 @@ pg.connect(assert.calls(function(err, client, release) {
3334
suite.test('cleanup', () => release())
3435
}));
3536

36-
pg.connect(assert.calls(function (err, client, release) {
37+
pool.connect(assert.calls(function (err, client, release) {
3738
assert.isNull(err);
3839
client.query("CREATE TEMP TABLE why(names text[], numbors integer[])");
3940
client.query(new pg.Query('INSERT INTO why(names, numbors) VALUES(\'{"aaron", "brian","a b c" }\', \'{1, 2, 3}\')')).on('error', console.log);
@@ -166,8 +167,7 @@ pg.connect(assert.calls(function (err, client, release) {
166167
assert.equal(names[2][0], 3);
167168
assert.equal(names[2][1], 100);
168169
release();
169-
pg.end();
170-
done();
170+
pool.end(done)
171171
}))
172172
})
173173

test/integration/client/cancel-query-tests.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/integration/client/huge-numeric-tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var helper = require('./test-helper');
2+
const pool = new helper.pg.Pool()
23

3-
helper.pg.connect(helper.config, assert.success(function(client, done) {
4+
pool.connect(assert.success(function(client, done) {
45
var types = require('pg-types');
56
//1231 = numericOID
67
types.setTypeParser(1700, function(){
@@ -14,7 +15,7 @@ helper.pg.connect(helper.config, assert.success(function(client, done) {
1415
client.query('INSERT INTO bignumz(id) VALUES ($1)', [bignum]);
1516
client.query('SELECT * FROM bignumz', assert.success(function(result) {
1617
assert.equal(result.rows[0].id, 'yes')
17-
helper.pg.end();
1818
done();
19+
pool.end()
1920
}))
2021
}));

test/integration/client/json-type-parsing-tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var helper = require('./test-helper');
22
var assert = require('assert');
33

4-
helper.pg.connect(assert.success(function (client, done) {
4+
const pool = new helper.pg.Pool()
5+
pool.connect(assert.success(function (client, done) {
56
helper.versionGTE(client, '9.2.0', assert.success(function (jsonSupported) {
67
if (!jsonSupported) {
78
console.log('skip json test on older versions of postgres');
@@ -20,7 +21,7 @@ helper.pg.connect(assert.success(function (client, done) {
2021
assert.strictEqual(row.alive, value.alive);
2122
assert.equal(JSON.stringify(row.now), JSON.stringify(value.now));
2223
done();
23-
helper.pg.end();
24+
pool.end()
2425
}));
2526
}));
2627
}));
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
var helper = require(__dirname + '/test-helper');
1+
var helper = require("./test-helper");
22
var pg = helper.pg;
3-
const suite = new helper.Suite()
3+
const suite = new helper.Suite();
4+
const pool = new pg.Pool();
45

5-
suite.test('can access results when no rows are returned', function() {
6-
var checkResult = function(result) {
7-
assert(result.fields, 'should have fields definition');
6+
suite.test("can access results when no rows are returned", function (done) {
7+
var checkResult = function (result) {
8+
assert(result.fields, "should have fields definition");
89
assert.equal(result.fields.length, 1);
9-
assert.equal(result.fields[0].name, 'val');
10+
assert.equal(result.fields[0].name, "val");
1011
assert.equal(result.fields[0].dataTypeID, 25);
11-
pg.end();
1212
};
1313

14-
pg.connect(assert.success(function(client, done) {
15-
const q = new pg.Query('select $1::text as val limit 0', ['hi'])
16-
var query = client.query(q, assert.success(function(result) {
17-
checkResult(result);
18-
done();
19-
}));
14+
pool.connect(
15+
assert.success(function (client, release) {
16+
const q = new pg.Query("select $1::text as val limit 0", ["hi"]);
17+
var query = client.query(q, assert.success(function (result) {
18+
checkResult(result);
19+
release();
20+
pool.end(done);
21+
})
22+
);
2023

21-
assert.emits(query, 'end', checkResult);
22-
}));
24+
assert.emits(query, "end", checkResult);
25+
})
26+
);
2327
});

test/integration/client/parse-int-8-tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ var helper = require('../test-helper');
33
var pg = helper.pg;
44
const suite = new helper.Suite()
55

6+
const pool = new pg.Pool(helper.config)
67
suite.test('ability to turn on and off parser', function() {
78
if(helper.args.binary) return false;
8-
pg.connect(helper.config, assert.success(function(client, done) {
9+
pool.connect(assert.success(function(client, done) {
910
pg.defaults.parseInt8 = true;
1011
client.query('CREATE TEMP TABLE asdf(id SERIAL PRIMARY KEY)');
1112
client.query('SELECT COUNT(*) as "count", \'{1,2,3}\'::bigint[] as array FROM asdf', assert.success(function(res) {
@@ -20,7 +21,7 @@ suite.test('ability to turn on and off parser', function() {
2021
assert.strictEqual('1', res.rows[0].array[0]);
2122
assert.strictEqual('2', res.rows[0].array[1]);
2223
assert.strictEqual('3', res.rows[0].array[2]);
23-
pg.end();
24+
pool.end();
2425
}));
2526
}));
2627
}));

test/integration/client/query-as-promise-tests.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@ process.on('unhandledRejection', function(e) {
66
process.exit(1)
77
})
88

9-
pg.connect(helper.config, assert.success(function(client, done) {
10-
client.query('SELECT $1::text as name', ['foo'])
11-
.then(function(result) {
12-
assert.equal(result.rows[0].name, 'foo')
13-
return client
14-
})
15-
.then(function(client) {
16-
client.query('ALKJSDF')
17-
.catch(function(e) {
18-
assert(e instanceof Error)
19-
client.query('SELECT 1 as num')
20-
.then(function (result) {
21-
assert.equal(result.rows[0].num, 1)
22-
done()
23-
pg.end()
24-
})
25-
})
26-
})
27-
}))
9+
const pool = new pg.Pool()
10+
const suite = new helper.Suite()
11+
12+
suite.test('promise API', (cb) => {
13+
pool.connect().then((client) => {
14+
client.query('SELECT $1::text as name', ['foo'])
15+
.then(function (result) {
16+
assert.equal(result.rows[0].name, 'foo')
17+
return client
18+
})
19+
.then(function (client) {
20+
client.query('ALKJSDF')
21+
.catch(function (e) {
22+
assert(e instanceof Error)
23+
client.query('SELECT 1 as num')
24+
.then(function (result) {
25+
assert.equal(result.rows[0].num, 1)
26+
client.release()
27+
pool.end(cb)
28+
})
29+
})
30+
})
31+
})
32+
})

0 commit comments

Comments
 (0)