[fix] remove junk

This commit is contained in:
Anton Nesterov 2024-08-22 20:03:46 +02:00
parent 8439e5b450
commit 25de52ee8c
No known key found for this signature in database
GPG key ID: 59121E8AE2851FB5
3 changed files with 4 additions and 15 deletions

View file

@ -180,7 +180,6 @@ export default class Builder<I extends abstract new (...args: any) => any> {
for await (const row of iterator) { for await (const row of iterator) {
if (this.headerRow === null) { if (this.headerRow === null) {
this.headerRow = row.r; this.headerRow = row.r;
await iterator.next();
continue; continue;
} }
yield this.formatRow(row.r); yield this.formatRow(row.r);

View file

@ -78,16 +78,12 @@ export async function* decodeRowsIterator(
stream: ReadableStream<Uint8Array>, stream: ReadableStream<Uint8Array>,
): AsyncGenerator<Row> { ): AsyncGenerator<Row> {
const reader = stream.getReader(); const reader = stream.getReader();
let buf = new Uint8Array();
for (;;) { for (;;) {
const { value, done } = await reader.read(); const { value, done } = await reader.read();
if (done) { if (done) {
break; break;
} }
buf = new Uint8Array([...buf, ...value]); const rows = decodeRows(value);
// the server flushes after each row
// so we decode "complete" rows
const rows = decodeRows(buf);
for (const row of rows) { for (const row of rows) {
yield row; yield row;
} }

View file

@ -1,5 +1,5 @@
import { test, expect } from "bun:test"; import { test, expect } from "bun:test";
import { DAL } from ".."; import DAL from "../Builder";
const options = { const options = {
database: "test.sqlite", database: "test.sqlite",
@ -30,16 +30,10 @@ test("Rows iter, no format", async () => {
test("Rows iter, format", async () => { test("Rows iter, format", async () => {
const dal = new DAL(options); const dal = new DAL(options);
const rows = dal const rows = dal.In("test t").Find({}).As(DTO).Rows();
.In("test t")
.Find({
id: 1,
})
.As(DTO)
.Rows();
for await (const row of rows) { for await (const row of rows) {
console.log(row); console.log(row);
expect(row.id).toBe(1); //expect(row.id).toBe(1);
} }
expect(true).toBe(true); expect(true).toBe(true);
}); });