(
sql: string,
params: ReadonlyArray<unknown> = [],
rowMode: "object" | "array" = "object"
)
| 167 | }) |
| 168 | } |
| 169 | |
| 170 | const run = ( |
| 171 | sql: string, |
| 172 | params: ReadonlyArray<unknown> = [], |
| 173 | rowMode: "object" | "array" = "object" |
| 174 | ) => |
| 175 | Effect.try({ |
| 176 | try: () => { |
| 177 | const results: Array<any> = [] |
| 178 | for (const stmt of sqlite3.statements(db, sql)) { |
| 179 | let columns: Array<string> | undefined |
| 180 | sqlite3.bind_collection(stmt, params as any) |
| 181 | while (sqlite3.step(stmt) === WaSqlite.SQLITE_ROW) { |
| 182 | columns = columns ?? sqlite3.column_names(stmt) |
| 183 | const row = sqlite3.row(stmt) |
| 184 | if (rowMode === "object") { |
| 185 | const obj: Record<string, any> = {} |
| 186 | for (let i = 0; i < columns.length; i++) { |
| 187 | Rec.assignProperty(obj, columns[i], row[i]) |
| 188 | } |
| 189 | results.push(obj) |
| 190 | } else { |
| 191 | results.push(row) |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | return results |
| 196 | }, |
| 197 | catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") }) |
| 198 | }) |
| 199 | |
| 200 | return identity<SqliteConnection>({ |
no test coverage detected