(
sql: string,
params: ReadonlyArray<unknown> = [],
rowMode: "object" | "array" = "object"
)
| 140 | } |
| 141 | |
| 142 | const run = ( |
| 143 | sql: string, |
| 144 | params: ReadonlyArray<unknown> = [], |
| 145 | rowMode: "object" | "array" = "object" |
| 146 | ) => |
| 147 | Effect.try({ |
| 148 | try: () => { |
| 149 | const results: Array<any> = [] |
| 150 | for (const stmt of sqlite3.statements(db, sql)) { |
| 151 | let columns: Array<string> | undefined |
| 152 | sqlite3.bind_collection(stmt, params as any) |
| 153 | while (sqlite3.step(stmt) === WaSqlite.SQLITE_ROW) { |
| 154 | columns = columns ?? sqlite3.column_names(stmt) |
| 155 | const row = sqlite3.row(stmt) |
| 156 | if (rowMode === "object") { |
| 157 | const obj: Record<string, any> = {} |
| 158 | for (let i = 0; i < columns.length; i++) { |
| 159 | obj[columns[i]] = row[i] |
| 160 | } |
| 161 | results.push(obj) |
| 162 | } else { |
| 163 | results.push(row) |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | return results |
| 168 | }, |
| 169 | catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" }) |
| 170 | }) |
| 171 | |
| 172 | return identity<SqliteConnection>({ |
| 173 | execute(sql, params, transformRows) { |
no test coverage detected