method
SQL.Query.writable
writable(): WritableStream<string | ArrayBufferLike | TypedArray<ArrayBufferLike> | DataView<ArrayBufferLike>>;
PostgreSQL only. Starts a COPY ... FROM STDIN query and returns a stream that takes the bytes for the server, in the format that the statement names.
close() resolves when the server has stored the rows, and rejects with the server's error. abort() stores nothing. The connection runs nothing else until then, so always close or abort the stream. Bun aborts a stream that is still open when its transaction, savepoint or reservation ends.
Call it before the query starts. The query takes no parameters, and resolves with the row count in count.
await Bun.file("users.csv").stream().pipeTo(sql`COPY users FROM STDIN (FORMAT csv)`.writable());Referenced types
class WritableStream<W = any>
This Streams API interface provides a standard abstraction for writing streaming data to a destination, known as a sink. This object comes with built-in backpressure and queuing.