Questions tagged [slonik]

Node.js PostgreSQL client Slonik.

Node.js PostgreSQL client Slonik.

11 questions
6
votes
2 answers

How do I insert multiple records into my postgres database using Slonik?

I am a front end developer and this is my first time using Slonik with postgresql. I want to know how I can make this query dynamic by inserting the data (which is hardcoded) using function parameters: const addMany = async (connection = slonik) =>…
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
3
votes
1 answer

Slonik dynamic insert query via sql tag

Via Slonik I try to create a sql statement in a dynamic way. I have a list of keys I want to use for my insert statement and to create a list of values. This is an example of my setup. Though the definition of my insert columns always fails. const…
Hoetmaaiers
  • 3,413
  • 2
  • 19
  • 29
2
votes
0 answers

How to enforce SLONIK to close open pools

THE PROBLEM I have a NodeJs server where I'm using jest for testing. In case of integration tests i get a message after all tests where passing: "Jest has detected the following X (15-20) open handles potentially keeping Jest from exiting" I knew…
2
votes
1 answer

How to pass a parameterized INTERVAL in a slonik/postgres query?

This query seems to be legal when I run it in Datagrip with a parameter value of '14 days' SELECT * FROM users WHERE users.updated_at < (CURRENT_DATE - INTERVAL $1) But trying to do something similar in slonik as below does not: const interval='14…
lamont
  • 428
  • 1
  • 7
  • 16
1
vote
1 answer

How to \COPY a CSV into a PostgreSQL Docker Container?

I'm trying to query a CSV into a DB, but always returns the error (No such file or directory). The file should be hosted on the /tmp folder on the container? Database: postgres:13.2-alpine (Docker container) Backend: node + slonik (on top of…
Newbie
  • 11
  • 2
1
vote
1 answer

How to connect to unix socket path in a connection string (slonik)?

Good Day! I got an error when I try to connect to db Google Cloud by dint of slonik: const pool = createPool( `socket:userName:password@/cloudsql/teest-123986:europe-west3:test?db=dbName` ) I got: error: throw new Error('SASL:…
Andres
  • 51
  • 1
  • 6
1
vote
0 answers

slonik- Module '"slonik"' has no exported member 'InterceptorType'

after updating slonik I got this error [ERROR] 00:03:35 ⨯ Unable to compile TypeScript: lib/newrelic/instrumentSlonik.ts(1,10): error TS2305: Module '"slonik"' has no exported member 'InterceptorType'. node_modules/ts-node-dev/lib/log.js:27 any…
Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
1
vote
1 answer

How do I add a conditional set clause to a slonik sql query?

I'm building a postgres query using slonik to update a user table. The passwordHash column should be changed only if the passwordHash variable is not null, otherwise it should be left untouched. I've tried with a nested rule: import { createPool,…
Federico Bellucci
  • 623
  • 2
  • 7
  • 26
1
vote
1 answer

slonik - Unexpected value expression

I am using slonik lib to run that query connection of DatabaseTransactionConnectionType const fileIds = ["3001"]; const noteId = 424; const query = sql` UPDATE file SET note_id = ${noteId} WHERE file_id in (${fileIds})`; await…
Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
0
votes
0 answers

How to run each test case in a separate transaction using slonik?

I'm trying to run tests in parallel using slonik. Each jest worker creates his own pool. All SQL queries in one test case must be executed inside a separate transaction. This will isolate jest workers from each other. The global setup script…
Ilya Ordin
  • 57
  • 5
0
votes
1 answer

How to generate dynamic and multiple Order By query in slonik

I am fetching an issue where I have to generate dynamic ORDER BY clause for multiple columns. Here is my sample query: SELECT * FROM user WHERE gender = 'male' ORDER BY created_at ASC, updated_at DESC LIMIT 10 OFFSET 0; Here, ORDER BY values will…
Md. Sajedul Karim
  • 6,749
  • 3
  • 61
  • 87