( client: Client, initSchema: SqliteSchema, testName: string, casing?: CasingType | undefined, )
| 2697 | }; |
| 2698 | |
| 2699 | export const introspectLibSQLToFile = async ( |
| 2700 | client: Client, |
| 2701 | initSchema: SqliteSchema, |
| 2702 | testName: string, |
| 2703 | casing?: CasingType | undefined, |
| 2704 | ) => { |
| 2705 | // put in db |
| 2706 | const { sqlStatements } = await applyLibSQLDiffs(initSchema); |
| 2707 | for (const st of sqlStatements) { |
| 2708 | client.execute(st); |
| 2709 | } |
| 2710 | |
| 2711 | // introspect to schema |
| 2712 | const introspectedSchema = await fromSqliteDatabase( |
| 2713 | { |
| 2714 | query: async <T>(sql: string, params: any[] = []) => { |
| 2715 | return (await client.execute({ sql, args: params })).rows as T[]; |
| 2716 | }, |
| 2717 | run: async (query: string) => { |
| 2718 | client.execute(query); |
| 2719 | }, |
| 2720 | }, |
| 2721 | undefined, |
| 2722 | ); |
| 2723 | |
| 2724 | const { version: initV, dialect: initD, ...initRest } = introspectedSchema; |
| 2725 | |
| 2726 | const initSch = { |
| 2727 | version: '6', |
| 2728 | dialect: 'sqlite', |
| 2729 | id: '0', |
| 2730 | prevId: '0', |
| 2731 | ...initRest, |
| 2732 | } as const; |
| 2733 | |
| 2734 | const initSn = squashSqliteScheme(initSch); |
| 2735 | |
| 2736 | const validatedCur = sqliteSchema.parse(initSch); |
| 2737 | |
| 2738 | const file = schemaToTypeScriptSQLite(introspectedSchema, 'camel'); |
| 2739 | |
| 2740 | fs.writeFileSync(`tests/introspect/libsql/${testName}.ts`, file.file); |
| 2741 | |
| 2742 | const response = await prepareFromSqliteImports([ |
| 2743 | `tests/introspect/libsql/${testName}.ts`, |
| 2744 | ]); |
| 2745 | |
| 2746 | const afterFileImports = generateSqliteSnapshot( |
| 2747 | response.tables, |
| 2748 | response.views, |
| 2749 | casing, |
| 2750 | ); |
| 2751 | |
| 2752 | const { version: v2, dialect: d2, ...rest2 } = afterFileImports; |
| 2753 | |
| 2754 | const sch2 = { |
| 2755 | version: '6', |
| 2756 | dialect: 'sqlite', |
no test coverage detected