From adc8bfa7bf8e9a8cc4f5c052bc0c240ab4e48837 Mon Sep 17 00:00:00 2001 From: brianc Date: Wed, 27 Oct 2010 18:58:58 -0500 Subject: [PATCH] start chopping up client to support prepared statements --- lib/client.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/client.js b/lib/client.js index bf4e22c0..3815dc79 100644 --- a/lib/client.js +++ b/lib/client.js @@ -76,7 +76,8 @@ p.pulseQueryQueue = function() { }; p.query = function(config) { - var query = new Query({text: config}); + //can take in strings or config objects + var query = new Query(config.text ? config : { text: config }); this.queryQueue.push(query); this.pulseQueryQueue(); return query; @@ -92,17 +93,29 @@ Client.md5 = function(string) { var Query = function(config) { this.text = config.text; + this.values = config.values; + this.rows = config.rows; + this.types = config.types; + this.name = config.name; //for code clarity purposes we'll declare this here though it's not //set or used until a rowDescription message comes in this.rowDescription = null; EventEmitter.call(this); }; -sys.inherits(Query, EventEmitter);p +sys.inherits(Query, EventEmitter); var p = Query.prototype; +p.isBoundCommand = function() { + return (this.values || 0).length > 0 || this.name || this.rows; +}; + p.submit = function(connection) { var self = this; - connection.query(this.text); + if(this.isBoundCommand()) { + throw new Error('Bound command not supported yet! :('); + } else { + connection.query(this.text); + } var handleRowDescription = function(msg) { self.onRowDescription(msg); };