Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

408
Views
¿Cómo se ejecutan los comandos psql en js?

Estoy tratando de ejecutar comandos psql en js. El objetivo sería ejecutar comandos como \c <database_name> o \i 'file.sql' . Entiendo que hay una biblioteca js que le permite conectarse a postgres (llamada pg). Sin embargo, parece que solo se conecta a una base de datos en postgres y no me permite ejecutar comandos psql. Por ejemplo tengo:

 import { Client } from 'pg'; export async function someFunction() { const client = new Client({ user: 'postgres', host: 'localhost', database: 'testDB', password: 'postgres', port: 5432 }); client.connect(); // this should populate my db given the test.sql file const res = await client.query(`\i ./test.sql`); console.log(res.rows); // This should return me the list of tables in the connected db const test = await client.query('\\dt public.*'); console.log("test: ", test); await client.end(); }

Aunque (dados estos documentos) debería estar completando mi db (line const res = await client.query(\i ./test.sql); ), obtengo este error: error: syntax error at or near "\" .
¿Cómo puedo ejecutar estos comandos en js (o en mi caso, ts).

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!