(sql: string, bindings: any[])
| 93 | }); |
| 94 | |
| 95 | const executeSingle = async (sql: string, bindings: any[]) => { |
| 96 | const results = []; |
| 97 | |
| 98 | for await (const stmt of sqlite3.statements(db, sql)) { |
| 99 | let columns; |
| 100 | const wrappedBindings = bindings ? [bindings] : [[]]; |
| 101 | |
| 102 | for (const binding of wrappedBindings) { |
| 103 | binding.forEach((b, index, arr) => { |
| 104 | if (typeof b == 'boolean') { |
| 105 | arr[index] = b ? 1 : 0; |
| 106 | } |
| 107 | }); |
| 108 | sqlite3.reset(stmt); |
| 109 | if (bindings) { |
| 110 | sqlite3.bind_collection(stmt, binding); |
| 111 | } |
| 112 | const rows = []; |
| 113 | |
| 114 | while ((await sqlite3.step(stmt)) === SQLite.SQLITE_ROW) { |
| 115 | const row = sqlite3.row(stmt); |
| 116 | rows.push(row); |
| 117 | } |
| 118 | |
| 119 | columns = columns ?? sqlite3.column_names(stmt); |
| 120 | if (columns.length) { |
| 121 | results.push({columns, rows}); |
| 122 | } |
| 123 | } |
| 124 | if (bindings) { |
| 125 | break; |
| 126 | } |
| 127 | } |
| 128 | const rows: any[] = []; |
| 129 | for (const resultRows of results) { |
| 130 | for (const row of resultRows.rows) { |
| 131 | const outRow: any = {}; |
| 132 | resultRows.columns.forEach((key, index) => (outRow[key] = row[index])); |
| 133 | rows.push(outRow); |
| 134 | } |
| 135 | } |
| 136 | const result = { |
| 137 | insertId: sqlite3.last_insert_id(db), |
| 138 | rowsAffected: sqlite3.changes(db), |
| 139 | rows: { |
| 140 | _array: rows, |
| 141 | length: rows.length, |
| 142 | item: (index: number) => rows[index], |
| 143 | }, |
| 144 | }; |
| 145 | return result; |
| 146 | }; |
| 147 | const _acquireExecuteLock = (callback: any) => { |
| 148 | return statementMutex.runExclusive(callback); |
| 149 | }; |
no outgoing calls
no test coverage detected
searching dependent graphs…