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
4
votes
2 answers

Node express & pg-promise - db.any is not a function

I have this error : TypeError: db.any is not a function I'm using node JS, with pg-promise and express. Here is the queries.js file (db) : const promise = require('bluebird'); var options = { promiseLib: promise }; var pgp =…
Antonin Mrchd
  • 656
  • 3
  • 9
  • 31
4
votes
1 answer

Query timeout in pg-promise

I want to add timeout to pg-promise queries so they will fail after some amount of time if database have not yet responded. Is there any recommended way to do that or should I make custom wrapper that will handle timer and reject promise if it's too…
Resure
  • 436
  • 7
  • 17
4
votes
1 answer

pg-promise one connection per user

Dear community and vitaly-t hopefully, I am building a website / server with pg-promise. I use postgre role/group login for authentification. I don't know if I am doing the things correctly but I would like that each user use their own postgres…
alexnode
  • 91
  • 9
4
votes
2 answers

pg-promise in AWS lambda

I am having quite a number of issues using pg-promise with AWS lambda. I wanted to understand how do I solve these issues. The library advises you to create one instance of the Database object and then export it from a module. There should only one…
sethu
  • 8,181
  • 7
  • 39
  • 65
4
votes
1 answer

pg-promise: use result of one query in next query within a transaction

I am node.js with pg-promise for postgres, trying to do a transaction with 2 inserts in sequence. The result id of the 1st insert should be used in the next insert in the transaction. Rollback if any of the query fails. Nesting 2nd db.none inside…
mythicalcoder
  • 3,143
  • 1
  • 32
  • 42
4
votes
1 answer

pg-promise: Pass a function as parameter to func()

I am using pg-promise to access our postgres database. I want to call a stored proc foo(geom) that accepts a geometry datatype (PostGIS). I only have lats/lngs to start with though, so I want to convert them using postGIS. This looks like…
Kevin
  • 775
  • 2
  • 13
  • 32
4
votes
1 answer

Query formatting for Parameterized Queries

I am using pg-promise to execute select query with like clause in PostgreSQL. Unfortunately the query is failing with error code as 08P01 and error message bind message supplies 1 parameters, but prepared statement "" requires 0 The query is as…
CuriousMind
  • 3,143
  • 3
  • 29
  • 54
4
votes
1 answer

Get a parents + children tree with pg-promise

I use the pg-promise library with bluebird for making dependent queries. I have two tables, a and b, looking like this: | a | | b | |-------| |-------| | a_id | | b_id | | prop1 | | prop2 | | b_a | where…
Krxldfx
  • 709
  • 1
  • 10
  • 23
4
votes
1 answer

How to make pg-promise return rows as arrays?

How can we make pg-promise return an array of rows from a query, as opposed to array of row objects?
hud
  • 51
  • 1
  • 4
4
votes
2 answers

How do you connect to a Postgres Database with no password using pg-promise?

I am trying to initialize a connection to my PG database doing this: pgp = require('pg-promise')({ // Initialization Options }), cn = { host: 'activity.postgres.activity', // server name or IP address; port: 5432, database:…
4
votes
1 answer

Parameterized query in Postgresql with a json array

I would like to invoke array_prepend into a json[] using a parameterized query. I am using pg-promise npm package but this uses the normal node-postgres adapter under the hood. My query is: db.query(`update ${schema}.chats set messages = …
arisalexis
  • 2,079
  • 2
  • 21
  • 42
3
votes
1 answer

Friendly stack traces with pg-promise for query errors

I am having an application that queries PostgreSQL database with an excellent pg-promise library. Is there a way to get a friendly stack trace in the case of query syntax contains errors? Either through Node configuration or pg-promise…
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
3
votes
2 answers

pg-promise transaction with dependent queries in forEach loop gives warning Error: Querying against a released or lost connection

I am trying to insert linked data in a pg-promise transaction. The transaction successfully inserts all the data correctly, but gives a warning UnhandledPromiseRejectionWarning: Error: Querying against a released or lost connection.. The code that…
deanna
  • 45
  • 6
3
votes
2 answers

How to rollback a transaction when a task in transaction fails with pg-promise

Let's say I have two functions: export const setThingAlertsInactive = (userID, thingIDs) => { return db.any(' UPDATE thing_alerts SET is_active = false WHERE IN (Select * from thing_alerts where user_id = $1 and thing_id IN ($2:csv))',…
ShadyAmoeba
  • 527
  • 1
  • 4
  • 15
3
votes
1 answer

pg-promise : Cancel a query initiated with pg-query-stream

I have a postgresql table fulled with thousands of time-series data each day. I have an app allowing user to retrieve those data. Queries can take up from 200ms to 30 sec depending on the time range, so these must be cancelable to avoid useless load…
Raphiki
  • 190
  • 3
  • 11