MCPcopy
hub / github.com/drizzle-team/drizzle-orm / introspectLibSQL

Function introspectLibSQL

drizzle-kit/src/cli/commands/introspect.ts:627–737  ·  view source on GitHub ↗
(
	casing: Casing,
	out: string,
	breakpoints: boolean,
	credentials: LibSQLCredentials,
	tablesFilter: string[],
	prefix: Prefix,
)

Source from the content-addressed store, hash-verified

625};
626
627export 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

Callers 1

schema.tsFile · 0.85

Calls 8

updateMethod · 0.95
prepareOutFolderFunction · 0.90
applyLibSQLSnapshotsDiffFunction · 0.90
squashSqliteSchemeFunction · 0.90
writeResultFunction · 0.90
connectToLibSQLFunction · 0.85
relationsToTypeScriptFunction · 0.85
joinFunction · 0.85

Tested by

no test coverage detected