(serializedMutations: SerializedMutation[])
| 360 | } |
| 361 | |
| 362 | async function writeMutations(serializedMutations: SerializedMutation[]) { |
| 363 | const response = { |
| 364 | tabId: serializedMutations[0].tabId, |
| 365 | outcome: 'success', |
| 366 | errorMessage: '', |
| 367 | } |
| 368 | |
| 369 | if (!database) { |
| 370 | response.outcome = 'error'; |
| 371 | response.errorMessage = 'No database selected'; |
| 372 | return response |
| 373 | } |
| 374 | |
| 375 | const transaction = (database.getType()) === 'sqlite' |
| 376 | ? await (database as SqliteEngine).transaction() |
| 377 | : await (database.getConnection())?.transaction(); |
| 378 | |
| 379 | if (!transaction) { |
| 380 | response.outcome = 'error'; |
| 381 | response.errorMessage = 'Could not start transaction'; |
| 382 | return response |
| 383 | } |
| 384 | |
| 385 | try { |
| 386 | await Promise.all(serializedMutations.map(async (serializedMutation) => { |
| 387 | if (!database) return; |
| 388 | return database.commitChange(serializedMutation, transaction); |
| 389 | })); |
| 390 | |
| 391 | await transaction.commit(); |
| 392 | } catch (error) { |
| 393 | response.outcome = 'error'; |
| 394 | response.errorMessage = String(error); |
| 395 | await transaction.rollback(); |
| 396 | } |
| 397 | |
| 398 | return response |
| 399 | } |
| 400 | |
| 401 | async function reconnect(webviewView: vscode.WebviewView) { |
| 402 | if (selectedProvider) { |
no test coverage detected