( client: Database, initSchema: SqliteSchema, testName: string, casing?: CasingType | undefined, )
| 2610 | }; |
| 2611 | |
| 2612 | export const introspectSQLiteToFile = async ( |
| 2613 | client: Database, |
| 2614 | initSchema: SqliteSchema, |
| 2615 | testName: string, |
| 2616 | casing?: CasingType | undefined, |
| 2617 | ) => { |
| 2618 | // put in db |
| 2619 | const { sqlStatements } = await applySqliteDiffs(initSchema); |
| 2620 | for (const st of sqlStatements) { |
| 2621 | client.exec(st); |
| 2622 | } |
| 2623 | |
| 2624 | // introspect to schema |
| 2625 | const introspectedSchema = await fromSqliteDatabase( |
| 2626 | { |
| 2627 | query: async <T>(sql: string, params: any[] = []) => { |
| 2628 | return client.prepare(sql).bind(params).all() as T[]; |
| 2629 | }, |
| 2630 | run: async (query: string) => { |
| 2631 | client.prepare(query).run(); |
| 2632 | }, |
| 2633 | }, |
| 2634 | undefined, |
| 2635 | ); |
| 2636 | |
| 2637 | const { version: initV, dialect: initD, ...initRest } = introspectedSchema; |
| 2638 | |
| 2639 | const initSch = { |
| 2640 | version: '6', |
| 2641 | dialect: 'sqlite', |
| 2642 | id: '0', |
| 2643 | prevId: '0', |
| 2644 | ...initRest, |
| 2645 | } as const; |
| 2646 | |
| 2647 | const initSn = squashSqliteScheme(initSch); |
| 2648 | |
| 2649 | const validatedCur = sqliteSchema.parse(initSch); |
| 2650 | |
| 2651 | const file = schemaToTypeScriptSQLite(introspectedSchema, 'camel'); |
| 2652 | |
| 2653 | fs.writeFileSync(`tests/introspect/sqlite/${testName}.ts`, file.file); |
| 2654 | |
| 2655 | const response = await prepareFromSqliteImports([ |
| 2656 | `tests/introspect/sqlite/${testName}.ts`, |
| 2657 | ]); |
| 2658 | |
| 2659 | const afterFileImports = generateSqliteSnapshot( |
| 2660 | response.tables, |
| 2661 | response.views, |
| 2662 | casing, |
| 2663 | ); |
| 2664 | |
| 2665 | const { version: v2, dialect: d2, ...rest2 } = afterFileImports; |
| 2666 | |
| 2667 | const sch2 = { |
| 2668 | version: '6', |
| 2669 | dialect: 'sqlite', |
no test coverage detected