make Query a public api

This commit is contained in:
Troy Kruthoff 2012-08-09 16:31:32 -07:00 committed by brianc
parent 312a3dd01c
commit e62eb9339b
3 changed files with 20 additions and 16 deletions

View File

@ -185,23 +185,12 @@ p._pulseQueryQueue = function() {
};
p.query = function(config, values, callback) {
//can take in strings or config objects
config = (typeof(config) == 'string') ? { text: config } : config;
if (this.binary && !('binary' in config)) {
config.binary = true;
//can take in strings, config object or query object
var query = (config instanceof Query) ? config : new Query(config, values, callback);
if (this.binary && !query.binary) {
query.binary = true;
}
if(values) {
if(typeof values === 'function') {
callback = values;
} else {
config.values = values;
}
}
config.callback = callback;
var query = new Query(config);
this.queryQueue.push(query);
this._pulseQueryQueue();
return query;

View File

@ -13,6 +13,7 @@ var PG = function(clientConstructor) {
EventEmitter.call(this);
this.Client = clientConstructor;
this.Connection = require(__dirname + '/connection');
this.Query = require(__dirname + '/query');
this.defaults = defaults;
};

View File

@ -5,7 +5,21 @@ var Result = require(__dirname + '/result');
var Types = require(__dirname + '/types');
var utils = require(__dirname + '/utils');
var Query = function(config) {
var Query = function(config, values, callback) {
// use of "new" optional
if (!(this instanceof Query)) return new Query(config, values, callback);
//can take in strings or config objects
config = (typeof(config) == 'string') ? { text: config } : config;
if(values) {
if(typeof values === 'function') {
callback = values;
} else {
config.values = values;
}
}
config.callback = callback;
this.text = config.text;
this.values = config.values;
this.rows = config.rows;