(operation: () => T)
| 2189 | } |
| 2190 | |
| 2191 | private transaction<T>(operation: () => T): T { |
| 2192 | if (this.databaseLease) return this.databaseLease.transaction('write', operation); |
| 2193 | this.db.exec('BEGIN IMMEDIATE'); |
| 2194 | try { |
| 2195 | const result = operation(); |
| 2196 | this.db.exec('COMMIT'); |
| 2197 | return result; |
| 2198 | } catch (error) { |
| 2199 | try { |
| 2200 | this.db.exec('ROLLBACK'); |
| 2201 | } catch { |
| 2202 | // Preserve the protocol failure that caused rollback. |
| 2203 | } |
| 2204 | throw error; |
| 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | private readTransaction<T>(operation: () => T): T { |
| 2209 | if (this.databaseLease) return this.databaseLease.transaction('read', operation); |
no test coverage detected