From 858b7a95f3757e2cbbc6455ba8b28593a29b5310 Mon Sep 17 00:00:00 2001 From: luaneko Date: Sat, 11 Jan 2025 00:39:00 +1100 Subject: [PATCH] Add streaming query testing code --- test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test.ts b/test.ts index 2f75455..6dff5e3 100644 --- a/test.ts +++ b/test.ts @@ -188,3 +188,22 @@ Deno.test(`transactions`, async () => { ); }); }); + +Deno.test(`streaming`, async () => { + await using pg = await connect(); + await using _tx = await pg.begin(); + + await pg.query`create table my_table (field text not null)`; + + for (let i = 0; i < 100; i++) { + await pg.query`insert into my_table (field) values (${i})`; + } + + let i = 0; + for await (const chunk of pg.query`select * from my_table`.chunked(10)) { + expect(chunk.length).toBe(10); + for (const row of chunk) expect(row.field).toBe(`${i++}`); + } + + expect(i).toBe(100); +});