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

Using node.js and promise to fetch paginated data

Please keep in mind that I am new to node.js and I am used with android development. My scenario is like this: Run a query against the database that returns either null or a value Call a web service with that database value, that offers info…
Alin
  • 14,809
  • 40
  • 129
  • 218
8
votes
1 answer

Synchronous programming using pg-promise

I am new to node.js and pg-promise coming from a synchronis programming background it requires a new thinking. I would to start with a scenario of running database initialisation before the main program logic. Following this…
Dercni
  • 1,216
  • 3
  • 18
  • 38
7
votes
2 answers

how do I close pg-promise connection in node.js after all tests have run in jest?

I need to close a PG-Promise database connection after testing a function in Jest. This is initialised in one place(db.js) and required everywhere it is needed. In the case of the code below, it is required by seed.js which seed.spec.js is…
James Wilson
  • 852
  • 13
  • 29
7
votes
2 answers

WHERE col IN Query with empty array as parameter

From example where-col-in example and this answer, WHERE IN clauses should have query with parameters with following syntax const response = await db.any('SELECT * FROM table WHERE id IN ($1:csv)', [data]) where data is an array. Now, when data is…
Naisheel Verdhan
  • 4,905
  • 22
  • 34
7
votes
2 answers

Node.js - PostgreSQL - could not determine data type of parameter $1 error

I'm trying to create a PostgreSQL prepared statement using node.js pg npm package. However, I keep getting an error: could not determine data type of parameter $1 function promiseQuery(sql, values) { return new Promise(function(resolve,…
wizard
  • 583
  • 2
  • 9
  • 26
6
votes
1 answer

Is it ok to be setting rejectUnauthorized to false in production PostgreSQL connections?

We recently moved to Heroku and upon attempting to connect our apps to the DB, it kept rejecting our queries with the message "Self signed certificate". Passing in rejectUnauthorized solved for this but now I'm wondering, should we be doing this in…
Matt Weber
  • 2,808
  • 2
  • 14
  • 30
6
votes
1 answer

How to set query_timeout in relation to statement_timeout?

We can set 2 timeouts for the Client: statement_timeout: number of milliseconds before a statement in query will time out, default is no timeout query_timeout number of milliseconds before a query call will timeout, default is no timeout I…
TmTron
  • 17,012
  • 10
  • 94
  • 142
6
votes
1 answer

pg-promise - Error operator does not exist: bigint = bigint[]

I am trying to run the query: let query = ` DELETE FROM ${table_name} WHERE _id IN ($1::bigint[]) AND account_id = $2 ` let fields = [ _ids, account_id, …
A. L
  • 11,695
  • 23
  • 85
  • 163
6
votes
2 answers

Optional column update if provided value for column is not null

I have following table: CREATE TABLE IF NOT EXISTS categories ( id SERIAL PRIMARY KEY, title CHARACTER VARYING(100) NOT NULL, description CHARACTER VARYING(200) NULL, category_type CHARACTER VARYING(100) NOT NULL ); I am using…
Alexey Vol
  • 1,723
  • 1
  • 16
  • 20
6
votes
3 answers

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

I'm new to node(express) and pg-promise, and have not been able to figure out how to add the result of each nested query(loop) into the main json array result query. I have two tables: Posts and comments. CREATE TABLE post( id serial, content text…
Sergio Rey
  • 83
  • 6
5
votes
1 answer

INSERT ON CONFLICT DO UPDATE using pg-promise helpers for multi row insert/update

I am trying to insert multiple rows to pgsql database using pg-promise. In my case, few records, which I am trying to insert, may exist already in the table. In such case, I need to update them. By going through the pg-promise official documentaion,…
Giri
  • 451
  • 1
  • 4
  • 13
5
votes
2 answers

Next.js API routes with pg-promise

I’m using the excellent pg-promise library inside a Next.js app to interface with a Postgres database deployed on AWS. Specifically, I’m using the API routes feature, where folders inside /pages/api are mapped to corresponding endpoints. This has…
mkrkelj1
  • 71
  • 4
5
votes
1 answer

Possible to add dynamic WHERE clause with a QueryFile?

I have a complex query stored in an SQL file and I would like to reuse it for various routes but change up the WHERE clause depending on the route. This would be instead of having a large complex query in multiple files with the only difference…
bergy
  • 1,395
  • 9
  • 11
5
votes
1 answer

JavaScript (Postgres DB) - How to use a prepared statement with an array as parameter in the WHERE IN ( ) clause

I am currently using the database class from http://vitaly-t.github.io/pg-promise/Database.html and trying to implement an Update statement using a PreparedStatment on my Postgres DB while having an Array passed to the WHERE IN clause ? const…
Azakaria
  • 51
  • 1
  • 3
5
votes
1 answer

Is it possible to "CREATE DATABASE ..." with pg-promise and PostgreSQL (9.5)?

Question is: 1) Can pg-promise be used to create a new database (schemas, et. al.)? Using node package 'pg-promise' I can't seem to figure out if it's possible to create a new database. I can connect to an existing database and have no issue…
Hawkeye64
  • 627
  • 1
  • 7
  • 17
1
2
3
34 35