( casing: Casing, out: string, breakpoints: boolean, credentials: SqliteCredentials, tablesFilter: string[], prefix: Prefix, )
| 513 | }; |
| 514 | |
| 515 | export const introspectSqlite = async ( |
| 516 | casing: Casing, |
| 517 | out: string, |
| 518 | breakpoints: boolean, |
| 519 | credentials: SqliteCredentials, |
| 520 | tablesFilter: string[], |
| 521 | prefix: Prefix, |
| 522 | ) => { |
| 523 | const { connectToSQLite } = await import('../connections'); |
| 524 | const db = await connectToSQLite(credentials); |
| 525 | |
| 526 | const matchers = tablesFilter.map((it) => { |
| 527 | return new Minimatch(it); |
| 528 | }); |
| 529 | |
| 530 | const filter = (tableName: string) => { |
| 531 | if (matchers.length === 0) return true; |
| 532 | |
| 533 | let flags: boolean[] = []; |
| 534 | |
| 535 | for (let matcher of matchers) { |
| 536 | if (matcher.negate) { |
| 537 | if (!matcher.match(tableName)) { |
| 538 | flags.push(false); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | if (matcher.match(tableName)) { |
| 543 | flags.push(true); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | if (flags.length > 0) { |
| 548 | return flags.every(Boolean); |
| 549 | } |
| 550 | return false; |
| 551 | }; |
| 552 | |
| 553 | const progress = new IntrospectProgress(); |
| 554 | const res = await renderWithTask( |
| 555 | progress, |
| 556 | fromSqliteDatabase(db, filter, (stage, count, status) => { |
| 557 | progress.update(stage, count, status); |
| 558 | }), |
| 559 | ); |
| 560 | |
| 561 | const schema = { id: originUUID, prevId: '', ...res } as SQLiteSchema; |
| 562 | const ts = sqliteSchemaToTypeScript(schema, casing); |
| 563 | const relationsTs = relationsToTypeScript(schema, casing); |
| 564 | |
| 565 | // check orm and orm-pg api version |
| 566 | |
| 567 | const schemaFile = join(out, 'schema.ts'); |
| 568 | writeFileSync(schemaFile, ts.file); |
| 569 | const relationsFile = join(out, 'relations.ts'); |
| 570 | writeFileSync(relationsFile, relationsTs.file); |
| 571 | console.log(); |
| 572 |
no test coverage detected