All Questions
Tagged with node.js postgresql
5,944
questions
133
votes
7
answers
261k
views
How to make connection to Postgres via Node.js
I find myself trying to create a postgres database, so I installed postgres and started a server with initdb /usr/local/pgsql/data, then I started that instance with postgres -D /usr/local/pgsql/data ...
99
votes
6
answers
69k
views
What is the proper way to use the node.js postgresql module?
I am writing a node.js app on Heroku and using the pg module. I can't figure out the "right" way to get a client object for each request that I need to query the database.
The documentation uses code ...
97
votes
8
answers
134k
views
ECONNREFUSED for Postgres on nodeJS with dockers
I'm building an app running on NodeJS using postgresql.
I'm using SequelizeJS as ORM.
To avoid using real postgres daemon and having nodejs on my own device, i'm using containers with docker-compose.
...
75
votes
18
answers
111k
views
Node.js, PostgreSQL error: no pg_hba.conf entry for host
I am following this article ((http://nodeexamples.com/2012/09/21/connecting-to-a-postgresql-database-from-node-js-using-the-pg-module/). I have already deployed my app to heroku and currently using ...
74
votes
7
answers
92k
views
TypeORM array is not supported in postgres?
I have a column kid_ages which is Integer[]. When migrating, I get the following error:
DataTypeNotSupportedError: Data type "Array" in "home.kid_ages" is not supported by "...
73
votes
6
answers
46k
views
Ordering results of eager-loaded nested models in Node Sequelize
I have a complex set of associated models. The models are associated using join tables, each with an attribute called 'order'. I need to be able to query the parent model 'Page' and include the ...
66
votes
23
answers
168k
views
Dialect needs to be explicitly supplied as of v4.0.0
I have been working on a NodeJS project which uses PostgreSQL database.
I am trying to implement migration to the database. Also, using Sequelize. After setting up the migration folder and config, it ...
65
votes
5
answers
38k
views
'Self signed certificate' error during query the Heroku hosted Postgres database from the Node.js application
My Node.js app is able to work with local Postgres database via npm pg module.
I can connect to the Heroku hosted Postgres database (free Hobby Dev plan) via command line with heroku pg:psql command ...
64
votes
5
answers
40k
views
Mongoose: Schema vs Model?
When looking at tutorials there is often a delineation between a schema and a model, particularly when dealing with mongoose/mongodb.
This makes porting over to postgresql somewhat confusing, as '...
61
votes
10
answers
87k
views
SSL for PostgreSQL connection nodejs
I am trying to connect to my Heroku PostgreSQL DB and I keep getting an SSL error. Does anyone have an idea on how to enable SSL in the connection string?
postgres://user:pass@host:port/database;
...
59
votes
3
answers
50k
views
Multi-row insert with pg-promise
I would like to insert multiple rows with a single INSERT query, for example:
INSERT INTO tmp(col_a,col_b) VALUES('a1','b1'),('a2','b2')...
Is there a way to do this easily, preferably for an array ...
54
votes
2
answers
67k
views
How do I define Sequelize.STRING length?
I want to define a length of a datatype in sequelize.
There is my source code :
var Profile = sequelize.define('profile', {
public_id: Sequelize.STRING,
label: Sequelize.STRING
})
It create a ...
53
votes
4
answers
61k
views
when to disconnect and when to end a pg client or pool
My stack is node, express and the pg module. I really try to understand by the documentation and some outdated tutorials. I dont know when and how to disconnect and to end a client.
For some routes I ...
52
votes
16
answers
100k
views
Connection "default" was not found with TypeORM
I use TypeORM with NestJS and I am not able to save properly an entity.
The connection creation works, postgres is running on 5432 port. Credentials are OK too.
However when I need to save a ...
49
votes
8
answers
53k
views
How do I properly insert multiple rows into PG with node-postgres?
A single row can be inserted like this:
client.query("insert into tableName (name, email) values ($1, $2) ", ['john', '[email protected]'], callBack)
This approach automatically comments out any ...
41
votes
4
answers
61k
views
Using group by and joins in sequelize
I have two tables on a PostgreSQL database, contracts and payments. One contract has multiple payments done.
I'm having the two following models:
module.exports = function(sequelize, DataTypes) {
...
40
votes
5
answers
63k
views
Import sql file in node.js and execute against PostgreSQL
I'm looking for an efficient way to take a raw sql file and have it executed synchronously against a postgres database, akin to if you ran it through psql.
I have an sql file which creates all ...
40
votes
1
answer
22k
views
Mongodb vs Postgres in Nodejs [closed]
I'm building a NodeJS application and am utterly torn between NoSQL MongoDB vs RMDS PostregresSql. My project is to create a open source example project for logging visitors and displaying visitor ...
39
votes
2
answers
35k
views
Verify database connection with pg-promise when starting an app
I am building an express application that connects to a postgres database using the pg-promise module.
I would like to ensure that the database connection is successful when starting the application ...
39
votes
1
answer
28k
views
How can I find the last insert ID with Node.js and Postgresql?
When issuing an "insert" statement to postgres, how can I get the ID of the row last inserted in the DB?
I tried "pg", "pg-native", "pg-connection", and a bunch of other packages. For each package, I ...
39
votes
8
answers
34k
views
Any Postgres compatible ORM for Node.js? [closed]
I'm seeking for a good ORM for postgres under Node.js, one that supports declaration of relationships beetween models, and fields validation. I've searched during a long time and cannot get any ...
36
votes
8
answers
66k
views
How to fix "Error: The server does not support SSL connections" when trying to access database in localhost?
I am following Heroku's node.js tutorial to provision a Postgres database.
After creating a simple table and connecting to localhost:5000/db, I get an error saying "Error: The server does not support ...
35
votes
4
answers
26k
views
How do I setup Babel 6 with Node JS to use ES6 in my Server Side code?
I have read several times the documentation provided at :
Node API Babel 6 Docs
I'm starting out learning pg-promise following the Learn by Example tutorial and would prefer to work with ES6 and ...
33
votes
10
answers
50k
views
QueryFailedError: the column "price" contain null values - TypeORM - PostgreSQL
I've created a simple table:
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"
@Entity()
export class Test {
@PrimaryGeneratedColumn()
public id!: number
@Column(...
33
votes
2
answers
53k
views
How to get enums in prisma client?
can I get a list of enums values of a model on the client-side like for select option?
Sample enum
enum user_type {
superadmin
admin
user
}
I want this as a select-option on the client-...
32
votes
5
answers
35k
views
node-postgres create database
I am using node-postgres, and at the beginning of my application I want to check whether the database exists or not. So my workflow idea is as following:
Check whether myDb is existing
If it is there,...
32
votes
2
answers
27k
views
Postgres Hstore vs. Redis - performance wise
I read about HStores in Postgres something that is offered by Redis as well.
Our application is written in NodeJS. Two questions:
Performance-wise, is Postgres HStore comparable to Redis?
for ...
32
votes
16
answers
107k
views
Nodemon - "clean exit - waiting for changes before restart" during setup
I am trying to set up a RESTful API with Node and Postgres. I have run into a problem where whenever I attempt to run the server (using npm start) to test it locally, I get the following output:
[...
31
votes
8
answers
16k
views
Authentication error when connecting to Heroku PostgreSQL database
I'm developing a Node.js application using PostgreSQL and hosting on Heroku. My problem is that I get an authentication error like so:
14:32:05 web.1 | { [error: no pg_hba.conf entry for host "...
31
votes
3
answers
48k
views
How to count a group by query in NodeJS Sequelize
In Rails I can perform a simple ORM query for the number of Likes a model has:
@records = Model
.select( 'model.*' )
.select( 'count(likes.*) as likes_count' )
.joins( '...
30
votes
2
answers
18k
views
typeORM: "message": "Data type \"Object\" in \"..." is not supported by \"postgres\" database."
Given the following entity definition:
@Entity()
export class User extends BaseEntity {
@Column({ nullable: true })
name!: string | null;
@Column()
age!: number;
}
The following error ...
28
votes
5
answers
27k
views
M1 Related! - Prisma: Can't reach database server at `database`:`5432`
Since I have moved to the new Apple Silicon architecture my docker setup with nextjs and postgres is not working anymore. The database inside the docker cannot be found by the nextjs server where I am ...
28
votes
2
answers
20k
views
how to make a like search in postgresql and node js
I am using node js and the module pg for connect to postrgresql
i want to make a search for a database of tags but i can't make it work,
in the variable tag i saved the param of the url , but the ...
28
votes
1
answer
53k
views
Avoid created_at and updated_at being auto generated by sequelize
How do I define a model for which created_at and updated_at are provided rather than generated?
I'm importing data from somewhere that already has data for created_at and updated_at fields that I ...
28
votes
16
answers
53k
views
RepositoryNotFoundError: No repository for "User" was found. Looks like this entity is not registered in current "default" connection? Typeorm
I am having a fun issue trying to get TypeOrm to work in my nestjs project.
I have the below code to configure my project, yes everything loads, and yes I am able to connect to my database.
import { ...
27
votes
7
answers
40k
views
“Error: Please install pg package manually” when trying to run “npm run serve:dev”?
I'm trying to run an app with script npm run serve:dev
but it gives an error Error: Please install pg package manually when trying to run npm run serve:dev
I already tried npm install -g pg','npm ...
27
votes
4
answers
34k
views
Use node-postgres to get Postgres "timestamp without timezone" in utc
I've got some timestamps stored as the Postgres type timestamp without time zone.
I'll use the timestamp 2013-12-20 20:45:27 as an example. I'm intending that this represent a UTC timestamp.
In psql,...
26
votes
6
answers
40k
views
Drop and create ENUM with sequelize correctly?
How to correctly drop and then recreate ENUM type with sequelize for Postgres in migrations? For example this migration doesn't drop enum_Users_status enum... so any attempts to recreate/change status ...
25
votes
1
answer
12k
views
node-postgres vs pg-promise for Nodejs Application
I'm going to build a Nodejs application with Postgresql as back end. I'm not going to use ORMs like Sequelize due to poor documentation and performance problems or any other ORM - ORM is an anti-...
25
votes
1
answer
19k
views
Inserting multiple records with pg-promise
I have a scenario in which I need to insert multiple records. I have a table structure like id (it's fk from other table), key(char), value(char). The input which needs to be saved would be array of ...
24
votes
5
answers
19k
views
Can't connect to heroku postgresql database from local node app with sequelize
I'm trying to connect to a Heroku postgresql database from a local nodejs app with Sequelize. I followed this two guides an everything is working perfectly fine on the heroky server side, but my node ...
24
votes
1
answer
29k
views
Composite primary key in Sequelize
Can someone suggest how do I set primary key on two columns within the same table.
var relation = {
'user_id': {
type: DataTypes.INTEGER
},
'organization_id':{
...
24
votes
4
answers
62k
views
Bind message supplies 1 parameters, but prepared statement "" requires 2
I have a database goods with two columns id jsonb primary_key and name.
Using this query:
const query = 'INSERT INTO "goods" (id, name) VALUES ($1, $2)'
together with the following data:
const data ...
23
votes
1
answer
61k
views
sequelize select and include another table alias
I'm using sequelize to acess a postgres database and I want to query for a city and for example include the "Building" table but I want to rename the output to "buildings" and return the http response ...
23
votes
4
answers
71k
views
How to do Bulk insert using Sequelize and node.js
js + sequelize to insert 280K rows of data using JSON.
The JSON is an array of 280K. Is there a way to do bulk insert in chunks. I am seeing that it takes a lot of time to update the data. When i ...
23
votes
2
answers
21k
views
How to insert a PostGIS GEOMETRY Point in Sequelize ORM?
I am trying to insert a row in a table that has a geometry column in Sequelize.js ORM.
I have latitude, longitude and altitude and need to convert it to a point first so I can Insert it as a geometry.
...
23
votes
5
answers
37k
views
Easier way to update data with node-postgres?
I'm using the superb plugin node-postgres, https://github.com/brianc/node-postgres
I have this update rest call. I have a about 30 columns in my in my table. Is there any easier way to update these ...
22
votes
3
answers
31k
views
Is it possible to define default value in Sequelize migration?
There is no documentation details about addColumn options, so I'm trying this:
queryInterface.addColumn('OrderBackups', 'my_column', Sequelize.INTEGER, { defaultValue: 0 })
and it does not work.
ps: ...
21
votes
6
answers
42k
views
How can I get soft deleted entity from typeorm postgreSQL?
I am trying to get soft deleted doc from postgreSQL database using typeorm find, findOne or query builder get/getMany methods, but it always return undefined. Is there a way to get deleted value?
By ...
21
votes
4
answers
28k
views
Adding a column to an existing table in Node.js & Knex
I'm using Node.js and Knex to build a service for my router. However, I can't figure out how to add a column to an existing table, any help would be appreciated.
Also, I'm using PostgreSQL, but I don'...