MCPcopy Create free account
hub / github.com/Effect-TS/effect / executeStream

Function executeStream

packages/sql/sqlite-wasm/src/SqliteClient.ts:232–256  ·  view source on GitHub ↗
(sql, params, transformRows)

Source from the content-addressed store, hash-verified

230 return this.execute(sql, params, transformRows)
231 },
232 executeStream(sql, params, transformRows) {
233 function* stream() {
234 for (const stmt of sqlite3.statements(db, sql)) {
235 let columns: Array<string> | undefined
236 sqlite3.bind_collection(stmt, params as any)
237 while (sqlite3.step(stmt) === WaSqlite.SQLITE_ROW) {
238 columns = columns ?? sqlite3.column_names(stmt)
239 const row = sqlite3.row(stmt)
240 const obj: Record<string, any> = {}
241 for (let i = 0; i < columns.length; i++) {
242 Rec.assignProperty(obj, columns[i], row[i])
243 }
244 yield obj
245 }
246 }
247 }
248 return Stream.suspend(() => Stream.fromIteratorSucceed(stream()[Symbol.iterator]())).pipe(
249 transformRows
250 ? Stream.mapArray((chunk) => transformRows(chunk) as any)
251 : identity,
252 Stream.mapError((cause) =>
253 new SqlError({ reason: classifyError(cause, "Failed to execute statement", "stream") })
254 )
255 )
256 },
257 export: Effect.try({
258 try: () => sqlite3.serialize(db, "main"),
259 catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to export database", "export") })

Callers

nothing calls this directly

Calls 3

streamFunction · 0.70
classifyErrorFunction · 0.70
pipeMethod · 0.65

Tested by

no test coverage detected