mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
failing test for parameterized queries
This commit is contained in:
parent
c58037b514
commit
cc2ff042ef
@ -66,7 +66,13 @@ p._pulseQueryQueue = function() {
|
||||
return;
|
||||
}
|
||||
this._activeQuery = query;
|
||||
this._sendQuery(query.text);
|
||||
if(query.values) {
|
||||
//call native function
|
||||
this._sendQueryWithParams(query.text, query.values)
|
||||
} else {
|
||||
//call native function
|
||||
this._sendQuery(query.text);
|
||||
}
|
||||
}
|
||||
|
||||
var ctor = function(config) {
|
||||
@ -107,11 +113,13 @@ var connect = function(config, callback) {
|
||||
};
|
||||
|
||||
//event emitter proxy
|
||||
var NativeQuery = function(text) {
|
||||
var NativeQuery = function(text, values) {
|
||||
if(typeof text == 'object') {
|
||||
this.text = text.text;
|
||||
this.values = text.values;
|
||||
} else {
|
||||
this.text = text;
|
||||
this.values = values;
|
||||
}
|
||||
EventEmitter.call(this);
|
||||
};
|
||||
|
||||
@ -40,6 +40,7 @@ public:
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "_sendQuery", SendQuery);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "_sendQueryWithParams", SendQueryWithParams);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "end", End);
|
||||
|
||||
target->Set(String::NewSymbol("Connection"), t->GetFunction());
|
||||
@ -89,6 +90,16 @@ public:
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
//v8 entry point into Connection#_sendQueryWithParams
|
||||
static Handle<Value>
|
||||
SendQueryWithParams(const Arguments& args)
|
||||
{
|
||||
HandleScope scope;
|
||||
Connection *self = ObjectWrap::Unwrap<Connection>(args.This());
|
||||
printf("%d\n", args.Length());
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
//v8 entry point into Connection#end
|
||||
static Handle<Value>
|
||||
End(const Arguments& args)
|
||||
|
||||
@ -26,20 +26,22 @@ test('connects', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('multiple results', function() {
|
||||
var setupClient = function() {
|
||||
var client = new Client(conString);
|
||||
client.connect();
|
||||
client.query("CREATE TEMP TABLE boom(name varchar(10))");
|
||||
client.query("INSERT INTO boom(name) VALUES('Aaron')");
|
||||
client.query("INSERT INTO boom(name) VALUES('Brian')");
|
||||
return client;
|
||||
}
|
||||
test('multiple results', function() {
|
||||
test('queued queries', function() {
|
||||
client.query("CREATE TEMP TABLE boom(name varchar(10))");
|
||||
client.query("INSERT INTO boom(name) VALUES('Aaron')");
|
||||
client.query("INSERT INTO boom(name) VALUES('Brian')");
|
||||
var client = setupClient();
|
||||
var q = client.query("SELECT * from BOOM");
|
||||
assert.emits(q, 'row', function(row) {
|
||||
assert.equal(row.name, 'Aaron');
|
||||
assert.emits(q, 'row', function(row) {
|
||||
assert.equal(row.name, "Brian");
|
||||
|
||||
})
|
||||
})
|
||||
assert.emits(q, 'end', function() {
|
||||
@ -55,3 +57,31 @@ test('multiple results', function() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('parameterized queries', function() {
|
||||
test('with a single string param', function() {
|
||||
var client = setupClient();
|
||||
var q = client.query("SELECT name FROM boom WHERE name = $1", ['Brian']);
|
||||
assert.emits(q, 'row', function(row) {
|
||||
assert.equal(row.name, 'Brian')
|
||||
})
|
||||
assert.emits(q, 'end', function() {
|
||||
client.end();
|
||||
});
|
||||
})
|
||||
test('with object config for query', function() {
|
||||
var client = setupClient();
|
||||
var q = client.query({
|
||||
text: "SELECT name FROM boom WHERE name = $1",
|
||||
values: ['Brian']
|
||||
});
|
||||
assert.emits(q, 'row', function(row) {
|
||||
assert.equal(row.name, 'Brian');
|
||||
})
|
||||
assert.emits(q, 'end', function() {
|
||||
client.end();
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user