pg-promise

pg-promise helpers : optionnal fields in insert and multiple-update

和自甴很熟 提交于 2021-01-29 02:29:17
问题 pg-promise helpers : optionnal fields in insert and multiple-update I have some question about non-required fields for insert and update statement INSERT STATEMENT With this post I defined a ColumnSet that contains optionals fields ( stype , sspeed , disup ). It works but I just want to know a little detail: You can see that the ColumnSet define the value of state as "false" if the object don't have the property. In the database the field "disup" is defined to "false" as default, so do I

Pg Promise timeout while using express generator format, but works fine with basic express sever

耗尽温柔 提交于 2020-12-16 07:03:20
问题 Pg-promise is Not returning anything for 60s and gets timed out while running server setup with express-generator. There are no error messages. All the routes without db.any or similar query, works fine. The routes with db.* times out. But, the same connection/route/query works perfectly with a simple express app. I am running this from AWS EC2. Here is the test sample express that worked fine. Same route in routes/index.js does not work - gets timed out. const express = require('express');

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

烂漫一生 提交于 2020-06-28 03:54:35
问题 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 causes this was originally: const item = { batch: { batch_number: 1 }, ingredients: [ { amount: '12', unit: 'kg' }, { amount: '4', unit: 'L' } ], } return await db.tx(async t => { const batchQueryString = pgp.helpers.insert(item.batch, null,

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

房东的猫 提交于 2020-06-28 03:54:03
问题 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 causes this was originally: const item = { batch: { batch_number: 1 }, ingredients: [ { amount: '12', unit: 'kg' }, { amount: '4', unit: 'L' } ], } return await db.tx(async t => { const batchQueryString = pgp.helpers.insert(item.batch, null,

Nested queries with pg-promises

扶醉桌前 提交于 2020-01-15 10:14:47
问题 I need to make a query with pg-promise using the result to make 3 others queries but i am getting this error when executing: Unhandled rejection TypeError: Method 'batch' requires an array of values. at batch (C:\apps\pfc\node_modules\spex\lib\ext\batch.js:61:26) at C:\apps\pfc\node_modules\spex\lib\ext\batch.js:149:26 at Task.batch (C:\apps\pfc\node_modules\pg-promise\lib\task.js:120:39).............. This is my code: db.task(t => { return t.one('select gid, idgrupo from orden where gid = $1

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

本小妞迷上赌 提交于 2020-01-14 09:45:08
问题 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 returns no data. What I want to be able to do is return the branch id after a successful insert, such as: INSERT into branch (columns) VALUES (values) RETURNING pk_branchID 回答1: Simply append the RETURNING... clause to the generated query: var h =

Difference between pg-promise 'duration' and execution time in EXPLAIN ANALYSE of postgres?

流过昼夜 提交于 2019-12-25 07:13:35
问题 I am using 'duration' property from data object of 'result' function to measure the duration of execution of my query. I tried the same query in pgAdmin with "EXPLAIN ANALYSE". Both have a big difference. can anyone say why is this? which is the right approach to measure the execution duration of my query. 回答1: EXPLAIN ANALYSE is a performance perspective internal to the server only. duration provided by method result of pg-promise includes: preparing the query for execution sending the query

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

吃可爱长大的小学妹 提交于 2019-12-25 02:26:10
问题 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 requirement. But I was not able to get the results from second query combined with the main query. I'm a beginner and would like to know the correct way of implementation. db.task(t => { const a = studies => t.any ('SELECT facility_contacts.name, facility

`WHERE col IN` with named parameters

点点圈 提交于 2019-12-24 08:39:58
问题 In the example on how to use parameterized queries with an IN clause, the syntax is as follows: const data = [1, 'two', 3, 'four']; db.any('SELECT * FROM table WHERE id IN ($1:csv)', [data]) .then(data => { ... I can't seem to get this to work for named parameters: db.manyOrNone('SELECT widget FROM widgets WHERE id IN ($(ids:list))', { ids: [1, 2, 3] }) (I'm using :list since it appears to be interchangeable with :csv ). I've tried various combinations like: ($(ids):list) (syntax error at or

Nested query object mapping with pg-promise

我的未来我决定 提交于 2019-12-23 03:02:31
问题 I'm going through an example from pg-promise for method map: // Build a list of active users, each with the list of user events: db.task(t => { return t.map('SELECT id FROM Users WHERE status = $1', ['active'], user => { return t.any('SELECT * FROM Events WHERE userId = $1', user.id) .then(events=> { user.events = events; return user; }); }).then(t.batch); }) .then(data => { // success }) .catch(error => { // error }); Let's say the Event entity has a one to many relationship with e.g. Cars ,