运行查询:
select * from employee where name = $1 and age = $2 and salary = $3;
问题查询:
select * from employee where name = $1 and age = $2;
我怎样才能写出一个
/* If $3 is PASSED Then ( and salary = $3) */
注:/ *我不能检查为空或空为$ 3不过去了那么$ 3将不能用于检查* /
在节点中我像这样使用
postGresAdaptor.executeQueryWithParameters(QUERY, QUERYPARAMS, function(error, result) {
if (error) {
callback(error);
} else {
data = result.data;
}
});
Run Code Online (Sandbox Code Playgroud)
不想在节点代码中添加逻辑,因为途中会有很多查询。
我已经找到了在rabittMq中发送字符串并从队列接收的示例,但是我不清楚这些方法-assertQueue,sendToQueue
send.js
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', function(err, conn) {
conn.createChannel(function(err, ch) {
var q = 'hello';
var msg = 'Hello World! - '+i;
ch.assertQueue(q, {durable: false});
ch.sendToQueue(q, new Buffer(msg));
console.log(" [x] Sent %s", msg);
});
setTimeout(function() { conn.close(); process.exit(0) }, 1000);
});
Run Code Online (Sandbox Code Playgroud)
receive.js
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', function(err, conn) { //amqp://localhost
conn.createChannel(function(err, ch) {
var q = 'hello';
ch.assertQueue(q, {durable: false});
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
ch.consume(q, function(msg) …Run Code Online (Sandbox Code Playgroud) ecmascript5中引入了export关键字:
var myFunc1 = function() { console.log('hello'); };
export.myFunc1 = myFunc1;
Run Code Online (Sandbox Code Playgroud)
如果我在 Firefox 控制台中运行上面的代码,则会出现错误:
SyntaxError: missing declaration after 'export' keyword
export.myFunc1 = myFunc1;
Run Code Online (Sandbox Code Playgroud)
我不明白我需要声明什么。
我是否以错误的方式使用它?
任何建议都会很好!
有没有办法从带有$参数的查询中获取可执行查询。实际上它很奇怪,但是我想在数据库中存储可执行查询。没有参数的完整查询($ 1,$ 2,$ 3)
我正在使用node-postgres
pg.connect(conString, function(err, client, done) {
console.log('Executing Insert query');
client.query('insert into tablename(column1,column2,column3) values($1,$2,$3)',["data1","data2","data3"], function(err, result) {
done();
console.log('finished executing Insert query');
});
});
Run Code Online (Sandbox Code Playgroud)
这就是我所需要的
insert into tablename(column1,column2,column3) values("data1","data2","data3")
Run Code Online (Sandbox Code Playgroud) node.js ×4
postgresql ×2
amqp ×1
chat ×1
ecmascript-5 ×1
javascript ×1
rabbitmq ×1
socket.io ×1
sql ×1
websocket ×1
where-clause ×1