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

Insert/update JSON into Postgresql column WHERE myvar = myval

I'm trying to insert JSON into a Postgresql column who's data type is JSON, but I'm having trouble finding how I can do this. This is as far as I've gotten but it's not correct because it just overwrites it every time, instead of adding a new key…
-1
votes
1 answer

How to construct conditional AND query to existing query with pg-promise

select statement with dynamic columns for where condition I need to do exactly what this answer says except my query is: export async function find_items_based_on_params(category,type,obj) { const q = 'SELECT * FROM $1 INNER JOIN category ON…
Varian
  • 1
  • 2
-1
votes
1 answer

pgpromise insert return message failed, but successfully inserted into table

pg-promise successfully inserted an row into table, but not showing insert return record. If i not use returning then all is fine. if using then error occurs. const createEMP = async (req, res, next) => { try{ let user = await db.none("insert…
jian
  • 4,119
  • 1
  • 17
  • 32
-1
votes
2 answers

Import * as pgPromise from 'pg-promise' in pg-promise example causes typescript error TS2349: This expression is not callable

Adapting the recommended typescript example in my program import * as pgPromise from 'pg-promise' ; const pg = pgPromise() ; did not work. The second line caused error: This expression is not callable. Type 'typeof pgPromise' has no call…
-1
votes
2 answers

How to split up Postgres data into JSON/object, or an easily usable format for Express

I'm using pg-promise to facilitate requests between Express and a Postgres database. Using pg-promise's any: db.any('select * from blog') .then(function (data) { console.log(data); }) .catch(function (error) { console.log('ERROR:',…
rpivovar
  • 3,150
  • 13
  • 41
  • 79
-1
votes
1 answer

take id from select query in pg promise

when i log data.id the result is undefined when i log data the result is [ anonymous { id: 23, username: 'vvv', password: '1', description: null, cutprice: null, salname: null, image: null, counter: 0 }…
jadlmir
  • 465
  • 1
  • 6
  • 16
-1
votes
1 answer

Does pg promise support WITH clause in query file?

If I put this in one query file how will pg promise handle it? WITH regional_sales AS ( SELECT region, SUM(amount) AS total_sales FROM orders GROUP BY region ), top_regions AS ( SELECT region FROM…
Zanko
  • 4,298
  • 4
  • 31
  • 54
-2
votes
1 answer

NodeJs using express and pg-promise for postgresql?

I'm running NodeJS and pg-promise, and are trying to accomplish somethings like: db.any('SELECT * FROM t_user WHERE email=$1 NOT(SELECT email FROM t_user WHERE id= $2)', [email, id]) [and error syntax 'NOT'][1] how i can SELECT with WHERE NOT?
Duy Tran
  • 1
  • 1
-2
votes
2 answers

How are these three JavaScript function arguments use?

I've looked up JavaScript functions and arguments but couldn't find anything to help me understand a function like the one below. You can reference the original tutorial. createPuppy has three arguments: req, res and next. function createPuppy(req,…
Thomas
  • 349
  • 3
  • 11
-3
votes
1 answer

Assigning result of a resolved Promise to a variable

I have a service that has a function that returns a Promise; service.getStuff(); // returns a Promise of an array; I'm interested in the field 'cool stuff' In a separate service, I want to grab the result of that resolved promise and assign it to a…
user319407
  • 173
  • 1
  • 2
  • 4
-5
votes
2 answers

SQL query INSERT if NOT EXISTS with form params

I'm having an issue figuring out how to only add entries to my database if it's not already there. I found the NOT EXISTS method but It's not working. restaurantsModel.create = (req, res, next) => { console.log("from restaurants.Model",…
1 2 3
34
35