( casing: Casing, out: string, breakpoints: boolean, credentials: LibSQLCredentials, tablesFilter: string[], prefix: Prefix, )
| 625 | }; |
| 626 | |
| 627 | export const introspectLibSQL = async ( |
| 628 | casing: Casing, |
| 629 | out: string, |
| 630 | breakpoints: boolean, |
| 631 | credentials: LibSQLCredentials, |
| 632 | tablesFilter: string[], |
| 633 | prefix: Prefix, |
| 634 | ) => { |
| 635 | const { connectToLibSQL } = await import('../connections'); |
| 636 | const db = await connectToLibSQL(credentials); |
| 637 | |
| 638 | const matchers = tablesFilter.map((it) => { |
| 639 | return new Minimatch(it); |
| 640 | }); |
| 641 | |
| 642 | const filter = (tableName: string) => { |
| 643 | if (matchers.length === 0) return true; |
| 644 | |
| 645 | let flags: boolean[] = []; |
| 646 | |
| 647 | for (let matcher of matchers) { |
| 648 | if (matcher.negate) { |
| 649 | if (!matcher.match(tableName)) { |
| 650 | flags.push(false); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | if (matcher.match(tableName)) { |
| 655 | flags.push(true); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | if (flags.length > 0) { |
| 660 | return flags.every(Boolean); |
| 661 | } |
| 662 | return false; |
| 663 | }; |
| 664 | |
| 665 | const progress = new IntrospectProgress(); |
| 666 | const res = await renderWithTask( |
| 667 | progress, |
| 668 | fromSqliteDatabase(db, filter, (stage, count, status) => { |
| 669 | progress.update(stage, count, status); |
| 670 | }), |
| 671 | ); |
| 672 | |
| 673 | const schema = { id: originUUID, prevId: '', ...res } as SQLiteSchema; |
| 674 | const ts = sqliteSchemaToTypeScript(schema, casing); |
| 675 | const relationsTs = relationsToTypeScript(schema, casing); |
| 676 | |
| 677 | // check orm and orm-pg api version |
| 678 | |
| 679 | const schemaFile = join(out, 'schema.ts'); |
| 680 | writeFileSync(schemaFile, ts.file); |
| 681 | const relationsFile = join(out, 'relations.ts'); |
| 682 | writeFileSync(relationsFile, relationsTs.file); |
| 683 | console.log(); |
| 684 |
no test coverage detected