Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unsafe.cursor does not work #149

Closed
MPvHarmelen opened this issue Feb 15, 2021 · 1 comment
Closed

unsafe.cursor does not work #149

MPvHarmelen opened this issue Feb 15, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@MPvHarmelen
Copy link

MPvHarmelen commented Feb 15, 2021

When using cursor on a query created using unsafe, nothing happens: it never resolves and never calls the argument to cursor. See my MWE below:

const p = require("postgres");
const q = p("postgresql://postgres:example@localhost/demo");

// this works and prints every row
console.log("a:")
const a = q`select * from "aircrafts"`.cursor(async (row) => {
  console.log(row);
});

setTimeout(() => {
  // this never calls the argument to `cursor` and never resolves
  console.log("b:")
  const b = q.unsafe('select * from "aircrafts"').cursor(async (r) => console.log(r));
}, 1000);
Setting up
# docker-compose.yml
# Use postgres/example user/password credentials
version: '3.1'

services:

  db:
    image: postgres:9
    restart: always
    environment:
      POSTGRES_PASSWORD: example
    volumes:
      - ${PWD}/data:/var/lib/postgresql/data
    ports:
      - 5432:5432
  • Start postgres
mkdir -p ~/postgres/data
# copy above docker-compose.yml to ~/postgres/docker-compose.yml
cd ~/postgres;
docker-compose up -d;
  • Add a database called demo to postgres
docker-bash
# select the postgres db container
# install some dependencies
apt update
apt install curl unzip -y
# download a test db dump
curl https://edu.postgrespro.com/demo-small-en.zip > demo.zip
unzip demo.zip
# restore the test db
PGPASSWORD=example psql --username=postgres  -f demo-small-en-20170815.sql
@porsager porsager added the bug Something isn't working label Mar 23, 2021
@Minigugus
Copy link
Contributor

I don't know if it's related but the following code never resolves either (tested with 182b6f1):

await sql`wut`.cursor(row => console.log(row));

No warning is shown about an uncaught promise rejection, so it could explain why is wasn't reported before.
However, .stream doesn't have this bug:

await sql`wut`.stream(row => console.log(row));

I tested with different batch size, same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants