()
| 43 | } |
| 44 | |
| 45 | async isOkay(): Promise<boolean> { |
| 46 | try { |
| 47 | const db = this.getConnection(); |
| 48 | |
| 49 | if (!db) { |
| 50 | return false |
| 51 | } |
| 52 | |
| 53 | if (this.inMemory) { |
| 54 | return true |
| 55 | } |
| 56 | |
| 57 | const stats = await stat(this.dbPath); |
| 58 | const fileSizeGB = Math.round((stats.size / (1024 * 1024 * 1024) + Number.EPSILON) * 100) / 100; // Convert to GB and round to 2 decimal places |
| 59 | const size = 5; |
| 60 | |
| 61 | if (fileSizeGB > size) { |
| 62 | reportError(`Warning: SQLite database file size too big for database integrity check: ${fileSizeGB}GB. Maximum size is ${size}GB. Hence, database integrity not checked. File: ${this.dbPath}`); |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | return new Promise<boolean>((resolve, reject) => { |
| 67 | db.get('PRAGMA integrity_check;', (err, result) => { |
| 68 | if (err) { |
| 69 | reportError(`SQLite integrity check error: ${err}`); |
| 70 | resolve(false); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | resolve(result && result.integrity_check === 'ok'); |
| 75 | }); |
| 76 | }); |
| 77 | } catch (err) { |
| 78 | reportError(`SQLite OK-check error: ${err}`); |
| 79 | return false; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | async disconnect(): Promise<void> { |
| 84 | return new Promise((resolve, reject) => { |
no test coverage detected