Questions tagged [pg-promise]

Complete access layer to node-postgres via Promises/A+.

Built on top of node-postgres and its connection pool, this library translates their callback interface into one based on Promises/A+, while extending the protocol to a higher level, with automated connections and transactions management.

In addition, the library provides:

  • its own, more flexible query formatting;
  • event reporting for connectivity, errors, queries and transactions;
  • declarative approach to controlling query results;
  • support for all popular promise libraries.
521 questions
59
votes
3 answers

Multi-row insert with pg-promise

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:…
Bomaz
  • 1,871
  • 1
  • 17
  • 22
39
votes
2 answers

Verify database connection with pg-promise when starting an app

I am building an express application that connects to a postgres database using the pg-promise module. I would like to ensure that the database connection is successful when starting the application server. In other words, if the connection to the…
Steven L.
  • 2,045
  • 3
  • 18
  • 23
35
votes
4 answers

How do I setup Babel 6 with Node JS to use ES6 in my Server Side code?

I have read several times the documentation provided at : Node API Babel 6 Docs I'm starting out learning pg-promise following the Learn by Example tutorial and would prefer to work with ES6 and transpile to ES5 with Babel but am unsure of a few…
Jax Cavalera
  • 801
  • 1
  • 8
  • 17
33
votes
4 answers

pg-promise returns integers as strings

I have this simple query to a table that contains a column of type bigint. However when I query it, pg-promise returns this column's values as a string. I can't find info about that in the documentation. Is that standard behavior? var ids = [180,…
Antoine
  • 5,055
  • 11
  • 54
  • 82
27
votes
2 answers

Where should I initialize pg-promise

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…
ggabor
  • 1,642
  • 4
  • 18
  • 23
25
votes
1 answer

Inserting multiple records with pg-promise

I have a scenario in which I need to insert multiple records. I have a table structure like id (it's fk from other table), key(char), value(char). The input which needs to be saved would be array of above data. example: I have some array objects…
Mandy
  • 582
  • 1
  • 5
  • 13
23
votes
1 answer

node-postgres vs pg-promise for Nodejs Application

I'm going to build a Nodejs application with Postgresql as back end. I'm not going to use ORMs like Sequelize due to poor documentation and performance problems or any other ORM - ORM is an anti-pattern. I found node-postgres and pg-promise are…
Abdisamad Khalif
  • 765
  • 2
  • 7
  • 19
13
votes
1 answer

Log specific postgresql query using pg-promise

I am using pg-promise package with Nodejs to execute PostgreSQL queries. I want to see the queries executed. Only specific queries, say, just one query that I want to debug. I can see that one recommended way is to use the pg-monitor to catch the…
mythicalcoder
  • 3,143
  • 1
  • 32
  • 42
13
votes
1 answer

,column is of type jsonb but expression is of type text[]

Have array as below, needs to be saved in JSONB column: [{"FoodType":"veg","pref":"High"} ,{"FoodType":"sea food","pref":"Medium"} ,{"FoodType":"Chicken","pref":"Low"}] I simply pass the req.body object (from Express) for insert to DB.…
sunil gupta
  • 173
  • 1
  • 1
  • 7
13
votes
2 answers

Pass an array of integers in array of parameters

I am trying to pass an array of parameters in pg-promise's array of parameters, as recommended in pg-promise docs. db.any("SELECT fieldname FROM table WHERE fieldname = $1 AND fieldname2 IN ($2)", …
13
votes
1 answer

How to get results from multiple queries at once with pg-promise?

Currently I have the following code to get the results of two queries dbro.many("SELECT geoname_id, country_name FROM paises WHERE locale_code=$1 LIMIT 10",data.lang) .then(function(countriesData){ data.countries=countriesData; …
David Noriega
  • 196
  • 1
  • 1
  • 7
12
votes
4 answers

NodeJS, promises, streams - processing large CSV files

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…
alphadogg
  • 12,762
  • 9
  • 54
  • 88
9
votes
1 answer

pg-promise number of updated rows

I am using the pg-promise NodeJS module. At some point, I am updating one of my database's table. I would like to know how many rows have been updated by the query, is it possible? Below is part of my code: var queryText = "UPDATE public.mytable SET…
nakurai
  • 155
  • 1
  • 9
9
votes
1 answer

NodeJS and pg-promise, catch PostgreSQL exceptions

I'm running NodeJS and pg-promise with a PostgreSQL backend. I've created my own TRIGGER which throws an exception in some cases. Things work fine at this end. But with pg-promise I have trouble catching the error's name. Using this…
Michael Nielsen
  • 1,194
  • 3
  • 22
  • 37
8
votes
3 answers

How to import pg-promise using ES6 syntax?

I am trying to set up a Postgres database in a nodejs server using ES6 syntax, but I don't think I'm importing and initializing pg-promise properly. If I were using common js sytax I would do the below: // Create Database Connection const pgp =…
Jack Kawell
  • 2,051
  • 1
  • 10
  • 13
1
2 3
34 35