pg-promise

NodeJS, promises, streams - processing large CSV files

拥有回忆 提交于 2019-11-27 01:40:25
问题 I need to build a function for processing large CSV files for use in a bluebird.map() call. Given the potential sizes of the file, I'd like to use streaming. This function should accept a stream (a CSV file) and a function (that processes the chunks from the stream) and return a promise when the file is read to end (resolved) or errors (rejected). So, I start with: 'use strict'; var _ = require('lodash'); var promise = require('bluebird'); var csv = require('csv'); var stream = require(

Where should I initialize pg-promise

我们两清 提交于 2019-11-26 22:45:33
I just started to learn nodejs-postgres and found the pg-promise package. I read the docs and examples but I don't understand where should I put the initialization code? I using Express and I have many routes. I have to put whole initialization (including pg-monitor init) to every single file where I would like to query the db or I need to include and initalize/configure them only in the server.js? If I initialized them only in the server.js what should I include other files where I need a db query? In other words. Its not clear to me if pg-promise and pg-monitor configuration/initalization

Where should I initialize pg-promise

ⅰ亾dé卋堺 提交于 2019-11-26 07:44:18
问题 I just started to learn nodejs-postgres and found the pg-promise package. I read the docs and examples but I don\'t understand where should I put the initialization code? I using Express and I have many routes. I have to put whole initialization (including pg-monitor init) to every single file where I would like to query the db or I need to include and initalize/configure them only in the server.js? If I initialized them only in the server.js what should I include other files where I need a

Multi-row insert with pg-promise

社会主义新天地 提交于 2019-11-26 00:25:38
问题 I would like to insert multiple rows with a single INSERT query, for example: INSERT INTO tmp(col_a,col_b) VALUES(\'a1\',\'b1\'),(\'a2\',\'b2\')... Is there a way to do this easily, preferably for an array of objects like these: [{col_a:\'a1\',col_b:\'b1\'},{col_a:\'a2\',col_b:\'b2\'}] I might end up with 500 records in one chunk, so running multiple queries would be undesirable. So far I have been able to do it for a single object only: INSERT INTO tmp(col_a,col_b) VALUES(${col_a},${col_b})