pgtyped
pgtyped copied to clipboard
feat: add support for streaming
Link to my feature request issue!
More context:
pg-cursor is maintained by the same author as pg and also part of his official documentation.
Links:
-
pg-cursoris documented onREADMEhttps://github.com/brianc/node-postgres -
pg-cursoris located in same monorepo aspghttps://github.com/brianc/node-postgres/tree/master/packages/pg-cursor -
Official
pg-cursordocumentation https://node-postgres.com/apis/cursor
Usage
import ( IDatabaseConnection } from "@pgtyped/runtime/lib/tag";
import { Client } from "pg";
import Cursor from "pg-cursor";
const client = new Client({ /* ... */ });
const connection: IDatabaseConnection = {
query: (query, bindings) => client.query(query, bindings),
stream: (query, bindings) => client.query(new Cursor(query, bindings)),
};
const getBigData = sql`SELECT * FROM big_data`;
const cursor = getBigData.stream({}, connection);
let rows = await cursor.read(1000);
while (rows.length) {
// Do something with the fetched rows...
// Then fetch another 1000 rows.
rows = await cursor.read(1000);
}
Fixes https://github.com/adelsz/pgtyped/issues/568
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| pgtyped | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Feb 7, 2024 3:28pm |
Maybe when I have time. Would appreciate if this got merged. Right now I patched it for my client using pnpm patch. I'll end my contract this friday. Maybe after I can add it.
Thanks @EloB