porsager / porsager/postgres

Cannot get count of COPY query

Open
#465 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

v4
Dominant language
JavaScript
Stars
8.7k
Forks
374
Avg merge
11d 16h
Merged PRs (30d)
1

Description

Hi @porsager thanks for making this library.

We are currently trying to migrate our data base code to this library and don't know how to get the count of a COPY query.

Our code looks like this:

const query = sql`COPY transaction (name) FROM STDIN`;
console.log(query.writeable); // undefined
console.log(await query); // Writeable

Normally one would use the .count property as described here https://github.com/porsager/postgres#count in the docs, but the problem is that in the example above await query is not a Result object but a Writeable (and thus has no .count property).

From the docs it seemed to me that one would have to call .writeable() on the query in order to get the stream but that's not what the console.log shows. I'm I missunderstanding something or should this behave differently?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the COPY query example and compare the documented .count and .writeable entry points with the behavior of await query. Verify what await query returns for COPY FROM STDIN and define done as a documented, usable way to obtain the copied-row count or a clear explanation of the supported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.