(
sql: string,
params: ReadonlyArray<unknown> = [],
rowMode: "object" | "array" = "object"
)
| 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, |
no test coverage detected