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
0
votes
1 answer

Combine file API with transactions for file saving or deleting

I am using node 8.11.1 with pg-promise 8.4.4 to handle queries and transactions in PostgreSQL. This is about node, but I guess is the same logic in other servers/tools too. The scenario is common. I want to save an image file in a folder, then if…
slevin
  • 4,166
  • 20
  • 69
  • 129
0
votes
1 answer

Bulk update to Postgres with node js performance issue

I'm facing performance issue while trying to do bulk update in PostgresDB. It's taking more than 180 seconds to update around 23000 records. PFB the code. I'm using pg-promise library. Is there anything I could do to improve the performance? const…
Abirami
  • 223
  • 6
  • 21
0
votes
2 answers

NodeJS async/await and function call

I'm running NodeJS with pg-promise for accessing my PostgreSQL. This is my test, which fails with undefined: function a() { pgPromise.one('SELECT 1') .then(row => { return row; }) .catch(error => { console.log(error); …
Alfred Balle
  • 1,135
  • 4
  • 16
  • 32
0
votes
1 answer

pg-promise - Not resolving multiple queries

I'm in the process of creating a mass mailer that allows a company to send out an email template to a specific plan that contains X amount of subscribers. However, when using pg-promise, I can't figure how to loop through an array that contains one…
Matt Carlotta
  • 18,972
  • 4
  • 39
  • 51
0
votes
1 answer

pg-promise: support polymorphic types

I have the following polymorphic function: CREATE OR REPLACE FUNCTION check_value_existence( p_value anynonarray, p_column_name information_schema.sql_identifier, p_table_name name, p_schema_name information_schema.sql_identifier…
SONewbiee
  • 363
  • 2
  • 15
0
votes
1 answer

Mocha --watch tests result in database error

I have a node.js (v10.8.0) app running express, and am testing it with mocha/chai. I'd like mocha to run tests every time there is a file change. My database (postgres) is initialized like this in db.js: const pg = require('pg-promise')(); const db…
Mark Karavan
  • 2,654
  • 1
  • 18
  • 38
0
votes
1 answer

Parsing PostgreSQL response from any() into JS object

When I call: db.any('SELECT (col1, col2, col3) FROM myTable....[other conditions]') where db is an instance of pg-promise connection, as a promise result for .then(function(data)) { I get an array with objects like { row: '(ans1,ans2,ans3)' } It is…
Jacob
  • 109
  • 2
  • 11
0
votes
0 answers

pg-promise formatter for WHERE and UPDATE SET clauses

Is there a formatter of pg-promise to format logical clauses especially in WHERE clauses, and SET clauses (in sql UPDATE)? Like connecting multiple keys and values of an object passed alongside a WHERE clause with ANDs without repeated writing a…
sçuçu
  • 2,960
  • 2
  • 33
  • 60
0
votes
0 answers

pg-promise - Combining multiple queries giving multiple results for same primary key even when DISTINCT keyword is used

I have a task which combines multiple queries and it works fine. db.task(t => { const a = studies => t.any ('SELECT facility_contacts.contact_type, facility_contacts.name, facility_contacts.email, facility_contacts.phone FROM facility_contacts WHERE…
0
votes
2 answers

pg-promise - Combine multiple nested loop queries to parent array result

My question is based on Combine nested loop queries to parent array result - pg-promise. I'm having a similar scenario but have multiple queries to be combined to get my final results. Following is my code with which I tried to implement my…
0
votes
1 answer

Is it possible to get `INSERT oid count` data after INSERT command with pg-promise?

When I use psql, there is confirmation after INSERT command. For example: t34=# INSERT INTO t VALUES ('test'); INSERT 0 1 Is it possible to get this data (0, 1) with pg-promise package? P.S. I speak about output INSERT oid count
Max Block
  • 1,134
  • 3
  • 16
  • 23
0
votes
1 answer

Multi user connection in node-postgres/pg-promise

I wish to have connected more than 1 users at the same time, as follows: // in node-postgres const { Pool } = require('pg'); const pool_1 = new Pool({ user: 'dbuser_1', host: 'database.server.com', database: 'mydb', password:…
SONewbiee
  • 363
  • 2
  • 15
0
votes
0 answers

Wildcard characters and unaccent in pg-promise query

I use pg-promise@8.4.4 and I would like to have wildcard characters and the unaccent function of the PostgreSQL. My pl/pgsql query has something like WHERE unaccent(p.name) ILIKE (''%'' || unaccent($1) || ''%'')' I want to make it into a…
slevin
  • 4,166
  • 20
  • 69
  • 129
0
votes
0 answers

set timezone in pg-promise only once per client

I have a timestamp with timezone column in postgressql, named created , that the data are saved in UTC. I am using pg-promise 8.4.4 and I want to select the data, but set a different timezone for every client. The logic is that my angular app uses…
slevin
  • 4,166
  • 20
  • 69
  • 129
0
votes
0 answers

Bulk INSERT for records that don't exist, returning ID

I'm using pg-promise to process an array of data that I want to insert in table A. I'm having a hard time figuring out how to dynamically create this query that should only INSERT those values not already present in the table, while returning the ID…