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

Function run

packages/sql/sqlite-wasm/src/SqliteClient.ts:183–211  ·  view source on GitHub ↗
(
        sql: string,
        params: ReadonlyArray<unknown> = [],
        rowMode: "object" | "array" = "object"
      )

Source from the content-addressed store, hash-verified

181 }
182
183 const run = (
184 sql: string,
185 params: ReadonlyArray<unknown> = [],
186 rowMode: "object" | "array" = "object"
187 ) =>
188 Effect.try({
189 try: () => {
190 const results: Array<any> = []
191 for (const stmt of sqlite3.statements(db, sql)) {
192 let columns: Array<string> | undefined
193 sqlite3.bind_collection(stmt, params as any)
194 while (sqlite3.step(stmt) === WaSqlite.SQLITE_ROW) {
195 columns = columns ?? sqlite3.column_names(stmt)
196 const row = sqlite3.row(stmt)
197 if (rowMode === "object") {
198 const obj: Record<string, any> = {}
199 for (let i = 0; i < columns.length; i++) {
200 Rec.assignProperty(obj, columns[i], row[i])
201 }
202 results.push(obj)
203 } else {
204 results.push(row)
205 }
206 }
207 }
208 return results
209 },
210 catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
211 })
212
213 return identity<SqliteMemoryConnection>({
214 isTransaction: () => sqlite3.get_autocommit(db) === 0,

Callers 4

executeFunction · 0.70
executeRawFunction · 0.70
executeValuesFunction · 0.70
executeValuesUnpreparedFunction · 0.70

Calls 6

getRefMethod · 0.80
classifyErrorFunction · 0.70
sendFunction · 0.70
stepMethod · 0.65
pushMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected