node-postgres

SSL for PostgreSQL connection nodejs

喜欢而已 提交于 2019-11-30 11:19:09
问题 I am trying to connect to my Heroku PostgreSQL DB and I keep getting an SSL error. Does anyone have an idea on how to enable SSL in the connection string? postgres://user:pass@host:port/database; Been looking for it everywhere but it does not seem to be a very popular topic. By the way, I am running Nodejs and the node-pg module with its connection-pooled method: pg.connect(connString, function(err, client, done) { /// Should work. }); Comments are much appreciated. 回答1: You can achieve this

How do I properly insert multiple rows into PG with node-postgres?

十年热恋 提交于 2019-11-30 01:57:08
问题 A single row can be inserted like this: client.query("insert into tableName (name, email) values ($1, $2) ", ['john', 'john@gmail.com'], callBack) This approach automatically comments out any special characters. How do i insert multiple rows at once? I need to implement this: "insert into tableName (name, email) values ('john', 'john@gmail.com'), ('jane', 'jane@gmail.com')" I can just use js string operators to compile such rows manually, but then i need to add special characters escape

node-postgres with massive amount of queries

爷,独闯天下 提交于 2019-11-29 14:16:54
问题 I just started playing around with node.js with postgres, using node-postgres. One of the things I tried to do is to write a short js to populate my database, using a file with about 200,000 entries. I noticed that after sometime (less than 10 seconds), I start to get "Error: Connection terminated". I am not sure whether this is problem with how I use node-postgres, or if it's because I was spamming postgres. Anyway, here is a simple code that shows this behaviour: var pg = require('pg'); var

Manually promisifying pg.connect with Bluebird

a 夏天 提交于 2019-11-29 00:12:25
I want to promisify node-postgres' pg.connect method along with the inner connection.query method provided in the callback. I can .promisify the latter, but I need to implement the first one manually (if I'm missing something here, please explain). The thing is, I'm not sure if this code is correct or should be improved? The code is working, I just want to know if I'm using Bluebird as meant. // aliases var asPromise = Promise.promisify; // save reference to original method var connect = pg.connect.bind(pg); // promisify method pg.connect = function (data) { var deferred = Promise.defer();

Pass array from node-postgres to plpgsql function

若如初见. 提交于 2019-11-28 10:06:02
问题 The plpgsql function: CREATE OR REPLACE FUNCTION testarray (int[]) returns int as $$ DECLARE len int; BEGIN len := array_upper($1); return len; END $$ language plpgsql; The node-postgres query + test array: var ta = [1,2,3,4,5]; client.query('SELECT testarray($1)', [ta], function(err, result) { console.log('err: ' + err); console.log('result: ' + result); }); Output from node server: err: error: array value must start with "{" or dimension information result: undefined I also tried cast the

node-postgres: how to execute “WHERE col IN (<dynamic value list>)” query?

不羁的心 提交于 2019-11-27 03:42:32
I'm trying to execute a query like this: SELECT * FROM table WHERE id IN (1,2,3,4) The problem is that the list of ids I want to filter against is not constant and needs to be different at every execution. I would also need to escape the ids, because they might come from untrusted sources, though I would actually escape anything that goes in a query regardless of the trustworthiness of the source. node-postgres appears to work exclusively with bound parameters: client.query('SELECT * FROM table WHERE id = $1', [ id ]) ; this will work if I had a known number of values ( client.query('SELECT *

node-postgres: how to execute “WHERE col IN (<dynamic value list>)” query?

一曲冷凌霜 提交于 2019-11-26 10:40:56
问题 I\'m trying to execute a query like this: SELECT * FROM table WHERE id IN (1,2,3,4) The problem is that the list of ids I want to filter against is not constant and needs to be different at every execution. I would also need to escape the ids, because they might come from untrusted sources, though I would actually escape anything that goes in a query regardless of the trustworthiness of the source. node-postgres appears to work exclusively with bound parameters: client.query(\'SELECT * FROM