work on named queries
This commit is contained in:
parent
0d7822d1cd
commit
941b2e298d
@ -65,7 +65,10 @@ p._pulseQueryQueue = function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._activeQuery = query;
|
this._activeQuery = query;
|
||||||
if(query.values) {
|
if(query.name) {
|
||||||
|
this._sendPrepare(query.name, query.text, (query.values||[]).length);
|
||||||
|
}
|
||||||
|
else if(query.values) {
|
||||||
//call native function
|
//call native function
|
||||||
this._sendQueryWithParams(query.text, query.values)
|
this._sendQueryWithParams(query.text, query.values)
|
||||||
} else {
|
} else {
|
||||||
@ -109,6 +112,7 @@ var NativeQuery = function(text, values, callback) {
|
|||||||
if(typeof text == 'object') {
|
if(typeof text == 'object') {
|
||||||
this.text = text.text;
|
this.text = text.text;
|
||||||
this.values = text.values;
|
this.values = text.values;
|
||||||
|
this.name = text.name;
|
||||||
} else {
|
} else {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
@ -121,9 +125,6 @@ var NativeQuery = function(text, values, callback) {
|
|||||||
if(this.callback) {
|
if(this.callback) {
|
||||||
this.rows = [];
|
this.rows = [];
|
||||||
}
|
}
|
||||||
if(typeof this.text != 'string') {
|
|
||||||
throw new Error("No query text")
|
|
||||||
}
|
|
||||||
//normalize values
|
//normalize values
|
||||||
if(this.values) {
|
if(this.values) {
|
||||||
for(var i = 0, len = this.values.length; i < len; i++) {
|
for(var i = 0, len = this.values.length; i < len; i++) {
|
||||||
|
@ -75,6 +75,8 @@ public:
|
|||||||
NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect);
|
NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect);
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery);
|
NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery);
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "_sendQueryWithParams", SendQueryWithParams);
|
NODE_SET_PROTOTYPE_METHOD(t, "_sendQueryWithParams", SendQueryWithParams);
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(t, "_sendPrepare", SendPrepare);
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(t, "_sendQueryPrepared", SendQueryPrepared);
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "end", End);
|
NODE_SET_PROTOTYPE_METHOD(t, "end", End);
|
||||||
|
|
||||||
target->Set(String::NewSymbol("Connection"), t->GetFunction());
|
target->Set(String::NewSymbol("Connection"), t->GetFunction());
|
||||||
@ -177,6 +179,29 @@ public:
|
|||||||
return cString;
|
return cString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//v8 entry point into Connection#_sendPrepare
|
||||||
|
static Handle<Value>
|
||||||
|
SendPrepare(const Arguments& args)
|
||||||
|
{
|
||||||
|
HandleScope scope;
|
||||||
|
Connection *self = ObjectWrap::Unwrap<Connection>(args.This());
|
||||||
|
String::Utf8Value queryName(args[0]);
|
||||||
|
String::Utf8Value queryText(args[1]);
|
||||||
|
|
||||||
|
self->SendPrepare(*queryName, *queryText, 0);
|
||||||
|
|
||||||
|
return Undefined();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Handle<Value>
|
||||||
|
SendQueryPrepared(const Arguments& args)
|
||||||
|
{
|
||||||
|
HandleScope scope;
|
||||||
|
Connection *self = ObjectWrap::Unwrap<Connection>(args.This());
|
||||||
|
|
||||||
|
return Undefined();
|
||||||
|
}
|
||||||
|
|
||||||
//v8 entry point into Connection#end
|
//v8 entry point into Connection#end
|
||||||
static Handle<Value>
|
static Handle<Value>
|
||||||
End(const Arguments& args)
|
End(const Arguments& args)
|
||||||
@ -232,6 +257,11 @@ protected:
|
|||||||
return PQsendQueryParams(connection_, command, nParams, NULL, paramValues, NULL, NULL, 0);
|
return PQsendQueryParams(connection_, command, nParams, NULL, paramValues, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SendPrepare(const char *name, const char *command, const int nParams)
|
||||||
|
{
|
||||||
|
return PQsendPrepare(connection_, name, command, nParams, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
//flushes socket
|
//flushes socket
|
||||||
void Flush()
|
void Flush()
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ test("noData message handling", function() {
|
|||||||
|
|
||||||
var client = helper.client();
|
var client = helper.client();
|
||||||
|
|
||||||
client.query({
|
var q = client.query({
|
||||||
name: 'boom',
|
name: 'boom',
|
||||||
text: 'create temp table boom(id serial, size integer)'
|
text: 'create temp table boom(id serial, size integer)'
|
||||||
});
|
});
|
||||||
@ -13,6 +13,11 @@ test("noData message handling", function() {
|
|||||||
name: 'insert',
|
name: 'insert',
|
||||||
text: 'insert into boom(size) values($1)',
|
text: 'insert into boom(size) values($1)',
|
||||||
values: [100]
|
values: [100]
|
||||||
|
}, function(err, result) {
|
||||||
|
if(err) {
|
||||||
|
console.log(err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.query({
|
client.query({
|
||||||
|
Loading…
Reference in New Issue
Block a user