make Query a public api
This commit is contained in:
parent
312a3dd01c
commit
e62eb9339b
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
16
lib/query.js
16
lib/query.js
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user