(code: string)
| 423 | } |
| 424 | |
| 425 | async rawQuery(code: string): Promise<any> { |
| 426 | try { |
| 427 | const db = this.getConnection(); |
| 428 | if (!db) { |
| 429 | return Promise.reject('Cannot connect to database') |
| 430 | } |
| 431 | |
| 432 | return new Promise<any>((resolve, reject) => { |
| 433 | // Determine if the query is a SELECT or PRAGMA statement |
| 434 | const isSelect = /^\s*(SELECT|PRAGMA)\s+/i.test(code); |
| 435 | |
| 436 | if (isSelect) { |
| 437 | db.all(code, (err, rows) => { |
| 438 | if (err) { |
| 439 | reportError(`SQLite run arbitrary query error: ${err}`); |
| 440 | reject(err); |
| 441 | return; |
| 442 | } |
| 443 | resolve(rows); |
| 444 | }); |
| 445 | } else { |
| 446 | db.run(code, function (err) { |
| 447 | if (err) { |
| 448 | reportError(`SQLite run arbitrary query error: ${err}`); |
| 449 | reject(err); |
| 450 | return; |
| 451 | } |
| 452 | |
| 453 | // For non-SELECT queries, return information about the operation |
| 454 | resolve({ |
| 455 | changes: this.changes, |
| 456 | lastID: this.lastID |
| 457 | }); |
| 458 | }); |
| 459 | } |
| 460 | }); |
| 461 | } catch (err) { |
| 462 | reportError(`SQLite run arbitrary query error: ${err}`); |
| 463 | throw err; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | async beginTransaction(): Promise<Database> { |
| 468 | try { |
no test coverage detected