All Questions
Tagged with node-postgres node.js
215 questions
0
votes
1answer
20 views
Postgres syntax in node-postgres for function call
Here is how I call postgres from my node.js app using express
const db_pg = require("./db-pg");
app.get('/pg/', (req,res,next) => {
db_pg.query(req).then((body) => {
res.send(body);
...
0
votes
0answers
26 views
node postgres connection perfomance improvement
I am writing my backend using nodejs (express), and my database is PostgreSQL. I am using node-postres (pg) to connect to the postgres database.
Currently I am using the pg.Pool concept, so that I ...
0
votes
0answers
33 views
How to insert a row with one column value equal to an array using node-postgres
I am new to node-postgres and I want to insert a row in a table using node-postgres, where one column value is an array of strings and one an array of integers.
Earlier I used to use sequelize and ...
-1
votes
0answers
22 views
Why are only hard coded queries not returning an error when calling client.query in node-postgres?
I'm extracting a SQL query from a webpage using puppeteer. When I pass the parsed query into the node-postgres client query method, I always get the error syntax error at or near ".".
When I console....
0
votes
1answer
19 views
How to handle the postgres connection when heroku changes the DATABASE_URL
On Heroku Postgres there is written:
The value of your app’s DATABASE_URL config var might change at any time. You should not rely on this value either inside or outside your Heroku app.
I'm ...
0
votes
1answer
50 views
AssertionError: expected undefined to equal 201
I have a post user API (database is Postgres), it works well on postman without and error, I have bodyparser in my app.js, .type('json') but my test is returning AssertionError: expected undefined to ...
0
votes
0answers
16 views
Intesgration testing for postgres node.js app
I a have a node.js app that is connected to a postgres database using the npm package node-postgres. I found a second package called pg-testdb that allows you to write a script to create test tables ...
0
votes
1answer
18 views
How to use Postgres pooling on NodeJS/Express server
New to Postgres and the concept of transaction pooling in general. In the documentation, Postgres recommends using pool.query method for single queries, and also warns that "You must always return the ...
1
vote
1answer
30 views
Can I import the node-postgres module (pg) or is it CommonJS only? [duplicate]
I have been writing most of my APIs in old-school JavaScript using const var = require('var'). I am now writing my first API in ES6 syntax including using import rather than require. I always use the ...
0
votes
0answers
17 views
Is there a way I can restructure my createTable in node-postgresql
I have a postgres schema for my node-postgres project, I only have two tables without foreign key created (meetups and users tables). How can I write my code to make every table created with their ...
0
votes
0answers
61 views
Pool query returns undefined using node-postgres
I'm doing some query using pg (https://node-postgres.com/):
pool.query(someQuery, function (error, result) {
// some actions
}
Every result should have a rows array (we can read about that here ...
-1
votes
1answer
37 views
postgres update query is not working in node,js
I have an update query which seems to be not working. The underlying database used is postgres. Could you please check why it is not working? I have included my api and schema. Thanks in advance
...
0
votes
0answers
20 views
Lost connection with database using node-postgres
I having a problem with node-postgres, sometimes I lost connection from PG. To get it back, I always needs to restart server.
here is the code snippet:
const pg = require('pg');
let ...
0
votes
2answers
100 views
Async/await with function push not working [duplicate]
I have a problem with async - await.
What is happening?
I have a function of callback that a sends an array of objects, with valid objects and invalid objects to other function.
In the function, I ...
0
votes
0answers
26 views
node-postgres listen/notify gets timed out
I am trying to implement notify triggers in postgres , also using node-postgres to listen to db changes .
var pgConnection = 'postgres://' + DB_USER + ':' + DB_PASSWORD + '@' +
DB_HOST + ':' + ...
0
votes
0answers
18 views
Inserting a variable array of data into a PostgreSQL column
Got a shortcoming of brain.exe for some reason currently.
I am using Node.js and node-postgres to query my DB.
I am trying to insert an array of text, basically, into a PostgreSQL column.
logging ...
0
votes
2answers
21 views
Questions about callbacks in node js using node-postgres and render page
I have postgresSql with a table of users(username, password e administrator(boolean)). Once I make my query (SELECT * FROM users WHERE username=$1 AND password=$2') I would like to check if ...
2
votes
2answers
69 views
Not able to release postgres client using npm-postgres
Here is the code that I have tried.client.release() or client.end() is
giving me UnhandledPromiseRejectionWarning .I would want to release
the connection back to the pool or end it once data is ...
0
votes
0answers
43 views
Cannot connect to PostgreSQL via node-postgres on Ubuntu 18.04.1 LTS
Installed PostgreSQL, created a user foo with password foo, database foo with owner foo, and modified pg_hba.conf:
# Database administrative login by Unix domain socket
local all ...
1
vote
1answer
481 views
Using Async/Await with node-postgres
I am using node-postgres to query my database and would like to know how to use async/await and handle errors correctly
An example of my use is here with a very simple query
const { Pool } = require(...
0
votes
2answers
288 views
How to do insert with array in SQL with JavaScript Node?
i have a problem. I have an array and i want that each element to be a row from column;
Example:
My Array: const myArray = ['A', 'B', 'C', 'D'];
and result is:
Column1 |
--------------------------...
0
votes
0answers
30 views
Query node postgres does not work in docker
When I send a request to the server it seems that the query function is not executing therefore no data is returned from the server, that is when it is running in a docker container, because when I ...
0
votes
0answers
20 views
parameterized statements not working in postgresql npm
I'm attempting to run a query with parameters using the pg npm as seen in their documentation:
//parameterized statements
client.query('SELECT $1::text as twitter_handle', ['@briancarlson'], function(...
0
votes
0answers
51 views
LEFT OUTER JOIN returning no results
I have a query I prepared and have been working on. This query working in Psequel and PgAdmin, but will not work on my backend ( node js ) The library I am using with node js for the postgresql is ...
-1
votes
1answer
34 views
Compare data within multiple queries - Postgres Node.js
So I am creating an API endpoint where I send in two different types of data from the UI. One is a string and the other is an array containing upto 5 items. I need to compare the results across the ...
0
votes
1answer
129 views
Transactions with node pg and foreach loop and async await
I am trying to insert multiple rows in PostgreSQL using node pg. I am using transactions but my query is executing after a response. I tried async await with my function but it is not working
This is ...
0
votes
1answer
33 views
pg client.on('error' does not detect network disruption
My application connects to a database and listens for events, so it can execute the events. If the connection with the database drops, then it's supposed to be able to detect it with consumer.db.on('...
0
votes
0answers
42 views
INSERT and DELETE of multiple records using node-postgres
What do you think about this INSERT and DELETE of multiple records using node-postgres. I guided myself a little with this thread:
https://github.com/brianc/node-postgres/issues/957
but I'm not sure ...
0
votes
1answer
27 views
Error handling postresql and nodejs query
I seem to be struggling to handle any database errors within my app. I have a simple query that updates a users password
// Update Users Password
async function updatePassword(password, id) {
const ...
2
votes
0answers
117 views
Bulk psql data COPY from stdin in nodeJs
I need to load the data in psql db time-to-time via a node app.
I'm using node-postgres package, which seems to be working fine with INSERT statements.
Since my db_dum is huge, I need to move to COPY ...
0
votes
1answer
112 views
Using Knex with own pg connection pool
I would like to use knex as a query builder, but my project already handles its own connection pool.
I wish I could to do something like:
const { Client } = require('pg')
const client = new Client()...
2
votes
0answers
105 views
How to pool postgresql connections in nodejs with facade design pattern?
Hello i am writing simple web application using design similar to facade design pattern. Application is written in Typescript using nodejs, expressjs, node-postres and inversify. Let say i have this ...
0
votes
1answer
41 views
How to fix infinite Promise loop at end of client.release() in node-postgres?
Here is my code that I'm trying to implement using node-postgres:
return pool.connect().then((client) => {
// if (err) {
// throw err;
// }
let ...
0
votes
1answer
33 views
Node-postgres is connecting to localhost instead of AWS Postgres Instance
I am new to NodeJS and PostgreSQL, I would like to seek your help regarding to my problem connecting to AWS Postgres Instance. My Nodejs keeps on connecting to my localhost instead of AWS Postgres ...
0
votes
1answer
44 views
PG won't concatenate large SQL string
I am using Node-Postgres for building an online sign-in application. I can run the following Postgres code no problem using PSQL:
DO $$
BEGIN
IF (SELECT child.child_signedin FROM child WHERE ...
0
votes
2answers
215 views
Why do I need to use async/await twice in node-postgres
I wrote this code that seems to be working:
database.js
const {Pool} = require('pg');
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
module.exports = {
query: (text, ...
0
votes
1answer
43 views
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 ...
0
votes
1answer
56 views
How to fetch from two databases in a single request in koajs using pg.pool
I am trying to get a combined result from two tables of different databases.I am new to koajs and Node.js.
Below is my sample code what I am trying:
db/index.js
const { Pool } = require('pg')
const ...
0
votes
1answer
113 views
Passing array of records to Postgres in `node-postgres` without string concatenation?
I have got a Postgres function that accepts an array of a custom composite type. I have got it to work by generating a huge SQL text query, but past 100,000 array items, it fails. This could be either ...
0
votes
0answers
26 views
Tables/records created to GCloud DB via node-postgres not visible in psql
I have a Postgres database in Google Cloud which I am able to connect to and create tables in via psql and 3rd db tools like DBeaver.
I can also 'successfully' create tables and insert data via node-...
0
votes
1answer
35 views
Node-Postgres: Merge transaction statements into one to improve speed?
I am currently using node-postgres to INSERT and UPDATE lots of data to my PostgresDB. Transactions can be up to 15k statements long.
I am using transactions as outlined in the documentation:
...
0
votes
0answers
27 views
node postgres database query error
I am working on a project with node.js and Postgres using pg npm module. When I run my query, the query does not execute and does not return an error either. On postman, it just keeps querying and ...
1
vote
1answer
324 views
Nodejs postgres pg syntax error
As the title says, I'm running into a syntax error using node-postgres. Here's what the code looks like
const {Pool, Client} = require('pg')
const pool = new Pool({
user: '<user>',
host: '&...
1
vote
0answers
125 views
Cannot connect to pg database from ec2 instance using node-postgres
I am trying to query a pg database from a nodejs express app hosted on ec2 instance. I am using node-postgres library. However, I am getting this error:
error: no pg_hba.conf entry for host "xxx.xx....
0
votes
0answers
30 views
Node PG driver stops listening to database events
I have a NodeJS service that uses PostGreSQL's event notification functionality to listen to the database for certain actions, and then execute Node functions as a response. How to set this up is ...
1
vote
1answer
147 views
How to use JSONB operations with pg-promise
I'm struggling with pg-promise and getting it to work with JSONB. I'm using prepared statements, i've attempted two variations for this SQL command (i just wanna udpate the jsonb column with a new set ...
0
votes
0answers
22 views
Every query on pool is triggering on connection
I started using PostgreSQL now, i want to have a persistent connection between the client and the database, so i don't need to create and finish a connection on each query. I found out that Pool is ...
0
votes
1answer
71 views
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 ...
0
votes
0answers
162 views
node-postgres `date` type query not correct
I am running a PostgreSQL 10 on a Vagrant VM Installed Version: 2.1.1 with the following OS:
Distributor ID: Debian
Description: Debian GNU/Linux 9.4 (stretch)
Release: 9.4
Codename: ...
0
votes
0answers
169 views
Sequelize migrate failing due to dialect object Object not supported error
Background
I am creating a boilerplate express application. I have configured a database connection using pg and sequelize. When I add the cli and try to run sequlize db:migrate I get this error,
...