Add streaming query testing code
This commit is contained in:
parent
a88da00dec
commit
858b7a95f3
19
test.ts
19
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);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user