started working on specifying defaults
This commit is contained in:
parent
2fd220d8e2
commit
de5438e6f5
@ -6,6 +6,7 @@ var url = require('url');
|
||||
var Query = require(__dirname + '/query');
|
||||
var utils = require(__dirname + '/utils');
|
||||
|
||||
var defaults = require(__dirname + '/defaults');
|
||||
var Connection = require(__dirname + '/connection');
|
||||
|
||||
var parseConnectionString = function(str) {
|
||||
@ -24,14 +25,14 @@ var Client = function(config) {
|
||||
config = parseConnectionString(config)
|
||||
}
|
||||
config = config || {};
|
||||
this.user = config.user;
|
||||
this.database = config.database;
|
||||
this.port = config.port || 5432;
|
||||
this.host = config.host;
|
||||
this.user = config.user || defaults.user;
|
||||
this.database = config.database || defaults.database;
|
||||
this.port = config.port || defaults.port;
|
||||
this.host = config.host || defaults.host;
|
||||
this.queryQueue = [];
|
||||
this.connection = config.connection || new Connection({stream: config.stream || new net.Stream()});
|
||||
this.queryQueue = [];
|
||||
this.password = config.password || '';
|
||||
this.password = config.password || defaults.password;
|
||||
|
||||
//internal references only declared here for clarity
|
||||
this.lastBuffer = false;
|
||||
|
16
lib/defaults.js
Normal file
16
lib/defaults.js
Normal file
@ -0,0 +1,16 @@
|
||||
module.exports = {
|
||||
//database user's name
|
||||
user: '',
|
||||
//name of database to connect
|
||||
database: '',
|
||||
//database user's password
|
||||
password: '',
|
||||
//database port
|
||||
port: 5432,
|
||||
//number of rows to return at a time from a prepared statement's
|
||||
//portal. 0 will return all rows at once
|
||||
rows: 0,
|
||||
//number of connections to use in connection pool
|
||||
//0 will disable connection pooling
|
||||
poolSize: 10
|
||||
}
|
@ -31,5 +31,6 @@ var connect = function(config, callback) {
|
||||
module.exports = {
|
||||
Client: Client,
|
||||
Connection: require(__dirname + '/connection'),
|
||||
connect: connect
|
||||
connect: connect,
|
||||
defaults: require(__dirname + '/defaults')
|
||||
}
|
||||
|
43
test/integration/client/configuration-tests.js
Normal file
43
test/integration/client/configuration-tests.js
Normal file
@ -0,0 +1,43 @@
|
||||
require(__dirname + '/test-helper');
|
||||
var pg = require("index");
|
||||
|
||||
test('default values', function() {
|
||||
assert.same(pg.defaults,{
|
||||
user: '',
|
||||
database: '',
|
||||
password: '',
|
||||
port: 5432,
|
||||
rows: 0,
|
||||
poolSize: 10
|
||||
})
|
||||
test('are used in new clients', function() {
|
||||
var client = new pg.Client();
|
||||
assert.same(client,{
|
||||
user: '',
|
||||
database: '',
|
||||
password: '',
|
||||
port: 5432
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('modified values', function() {
|
||||
pg.defaults.user = 'boom'
|
||||
pg.defaults.password = 'zap'
|
||||
pg.defaults.database = 'pow'
|
||||
pg.defaults.port = 1234
|
||||
pg.defaults.host = 'blam'
|
||||
pg.defaults.rows = 10
|
||||
pg.defaults.poolSize = 0
|
||||
|
||||
test('are passed into created clients', function() {
|
||||
var client = new Client();
|
||||
assert.same(client,{
|
||||
user: 'boom',
|
||||
password: 'zap',
|
||||
database: 'pow',
|
||||
port: 1234,
|
||||
host: 'blam'
|
||||
})
|
||||
})
|
||||
})
|
@ -6,7 +6,9 @@ module.exports = {
|
||||
var client = new Client({
|
||||
database: helper.args.database,
|
||||
user: helper.args.user,
|
||||
password: helper.args.password
|
||||
password: helper.args.password,
|
||||
host: helper.args.host,
|
||||
port: helper.args.port
|
||||
});
|
||||
client.connect();
|
||||
return client;
|
||||
|
@ -4,8 +4,8 @@ test('client settings', function() {
|
||||
|
||||
test('defaults', function() {
|
||||
var client = new Client();
|
||||
assert.equal(client.user, null);
|
||||
assert.equal(client.database, null);
|
||||
assert.equal(client.user, '');
|
||||
assert.equal(client.database, '');
|
||||
assert.equal(client.port, 5432);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user