Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

docs: clarification on minimal example with full error handling

Abierto
#3,328 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
javascript, node.js, postgresql

Línea de trabajo

Comienza revisando las secciones existentes de la documentación que cubren Client, Pool, connect, query, end y error events. Compara esas secciones con los dos ejemplos mínimos del issue; la documentación estará completa cuando explique claramente el comportamiento relevante del manejo de errores y las ventajas y desventajas de usar Client o Pool para una sola consulta.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

question

The docs somewhat talk about it in pieces, but it wasn't 100% clear what a minimal code example with full error handling looks like, so I was hoping to get some clarity around that. I believe the following are both minimal examples, but I have a few questions surrounding them.

Client example:

import pg from 'pg';

const client = new pg.Client();

await client.connect();

try {
  await client.query('SELECT $1::text as message', ['Hello world!']);
} finally {
  await client.end();
}

Pool example:

import pg from 'pg';

const pool = new pg.Pool();

try {
  await pool.query('SELECT $1::text as message', ['Hello world!']);
} finally {
  await pool.end();
}

My couple questions:

  1. Does either example need an actual event listener for error, or because I'm calling connect -> query -> end directly after each other, is it not possible for an error event to actually be emitted? I know in normal case errors that happen during those are rejected with the promise, but I wasn't sure if it was actually possible for an error event to be emitted between say the connect and query calls, etc.
  2. Is there any advantage or disadvantage to using Pool even if it's only a single call and will then be torn down? The only advantage I can see is it requires one less line of code since you don't need to explicitly call connect, but I didn't know if there was other overhead or considered an antipattern*?

* I know instantiating a bunch of pools is an antipattern, but think of a usecase more akin to lambda or something, where it's not possible to keep a pool active, so I'm basically just spinning up some code, running a single query, then spinning everything down. Does using Pool have any negatives for that use case, or does defaulting to Pool over Client make sense?

Thanks for any info/help!

Lenguaje dominante
JavaScript
Estrellas
13.2k
Forks
1.4k
Merge medio
6 d 15 h
PR fusionados (30 d)
6

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de brianc/node-postgres

Todos los issues de brianc/node-postgres

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.