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

How to mock pg-promise library with jest

I am trying to mock the pg promise library. I want to be able mock return whether the promise rejects or resolves. Here is an example function and test: const pgp = require('pg-promise')({}); const someFunc = callback => { const db =…
John Smith
  • 103
  • 1
  • 4
5
votes
2 answers

Connection pool using pg-promise

I'm using Node js and Postgresql and trying to be most efficient in the connections implementation. I saw that pg-promise is built on top of node-postgres and node-postgres uses pg-pool to manage pooling. I also read that "more than 100 clients at…
michalDia
  • 61
  • 1
  • 6
5
votes
1 answer

How to return insert query result values using pg-promise helpers

I am using pgp.helpers.insert to save data into PostgreSQL which is working well. However, I need to return values to present in a response. I am using: this.collection.one(this.collection.$config.pgp.helpers.insert(values, null, 'branch')) which…
Faz
  • 360
  • 3
  • 11
5
votes
2 answers

PostgreSQL multi-value upserts

is it possible to perform a multi-value upsert in PostgreSQL? I know multi-value inserts exist, as do the "ON CONFLICT" key words to perform an update if the key is violated... but is it possible to bring the two together? Something like…
dvsoukup
  • 1,586
  • 15
  • 31
5
votes
1 answer

Postgresql Catching Transaction Error and Rollback

I am using pg-promise to run my SQL queries. The queries themselves are stored in external .sql files. When I execute a transaction, Postgres will abort the transaction if an error occurs (as expected). The problem that I'm running into is any…
mbhuiyan
  • 145
  • 2
  • 12
5
votes
1 answer

Return in pg-promise

I created a separate file with all my queries using pg-promise module for Node. While for most of them I just use req, res after a query, for one I want to return a value back. It does not work. It returns undefined. passportLogin: (email)=> { …
ocram
  • 1,384
  • 6
  • 20
  • 36
5
votes
2 answers

how should i do asynchronous unit testing?

I am using pg-promise. i am learnner please excuse if it seems trivial to you. how can i wrtie unit test for. it errors out data is undefined. i have been making connection in js file and export that module.another js file use to query against…
aka
  • 199
  • 1
  • 4
  • 15
5
votes
1 answer

Pg-promise performance boost : ON CONFLICT

I'm trying to follow the performance pattern recommended by the pg-promise library author here. Basically Vitaly recommends to do so with inserts : var users = [['John', 23], ['Mike', 30], ['David', 18]]; // We can use Inserts as an inline…
4
votes
3 answers

What can cause "idle in transaction" for "BEGIN" statements

We have a node.js application that connects via pg-promise to a Postgres 11 server - all processes are running on a single cloud server in docker containers. Sometimes we hit a situation where the application does not react anymore. The last time…
TmTron
  • 17,012
  • 10
  • 94
  • 142
4
votes
1 answer

Is there a way to Camel Case the column names returned from PostgreSQL using pg-promise?

When we execute queries to our PostgreSQL Database and receive responses, we then pass these responses to our clientside to display/work with. Example: const response = [ { first_name: 'Bob', last_name: 'English', title: 'The Dude', …
Matt Weber
  • 2,808
  • 2
  • 14
  • 30
4
votes
1 answer

Having Trouble Initializing Postgresql Database Through PG-Promise

I'm completely new to Express/Postgresql and I'm trying to learn them to create a web application. After some poking around, I decided that I wanted to develop my back-end with TypeScript. I successfully converted all my other files from JavaScript…
4
votes
1 answer

NodeJS, pg-promise and array as parameter

Running NodeJS and pg-promise. I've got an array: let my_array = new array('x', 'y', 'z'); I'm trying to pass this as a parameter to my PostgreSQL query with pg-promise: db_webhooks.any('SELECT cars FROM my_cars WHERE id IN ($1)', [my_array]) …
Alfred Balle
  • 1,135
  • 4
  • 16
  • 32
4
votes
2 answers

pg-promise wrong insertion of multipolygons into postgis database

So I am using pg-promise to insert multiple geojson MultiPolygons into a postgis database. The insertion into the database work fine, but for some of the row in the database I get a strange behaviour, that is the cell is filled with two lines. The…
bmblby
  • 41
  • 2
4
votes
2 answers

Pg-promise: proper way of returning result of query

I want to check whether a username is already in use using pg-promise. I use the following query: this.db.one('SELECT EXISTS(SELECT 1 FROM users WHERE username = $1)', username); I am trying to encapsulate this query inside a function that simply…
Kathandrax
  • 914
  • 14
  • 26
4
votes
1 answer

Stubbing pg-promise using sinon and mocha

Suppose I have a the following module, as database.js const initOptions = {} const pgp = require('pg-promise')(initOptions) const config = require('../../config') const db = pgp({ host: config.database.host, port: config.database.port, …
MadsRC
  • 197
  • 1
  • 12
1 2
3
34 35