(client: TestDatabaseClient)
| 35 | } |
| 36 | |
| 37 | export async function resetTestDatabaseClient(client: TestDatabaseClient): Promise<void> { |
| 38 | const schemaObjects = await client.execute(` |
| 39 | SELECT type, name |
| 40 | FROM sqlite_master |
| 41 | WHERE name NOT LIKE 'sqlite_%' |
| 42 | AND type IN ('table', 'view', 'trigger') |
| 43 | ORDER BY CASE type WHEN 'trigger' THEN 0 WHEN 'view' THEN 1 ELSE 2 END |
| 44 | `); |
| 45 | |
| 46 | await client.execute('PRAGMA foreign_keys = OFF'); |
| 47 | try { |
| 48 | for (const row of schemaObjects.rows) { |
| 49 | const type = String(row.type).toUpperCase(); |
| 50 | if (type !== 'TABLE' && type !== 'VIEW' && type !== 'TRIGGER') { |
| 51 | continue; |
| 52 | } |
| 53 | const name = String(row.name).replace(/"/g, '""'); |
| 54 | await client.execute(`DROP ${type} IF EXISTS "${name}"`); |
| 55 | } |
| 56 | } finally { |
| 57 | await client.execute('PRAGMA foreign_keys = ON'); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | export async function closeTestDatabaseClient(client: TestDatabaseClient): Promise<void> { |
| 62 | await enqueueTestDatabaseOperation(async () => { |
no test coverage detected
searching dependent graphs…