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

Function introspectSqlite

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

Source from the content-addressed store, hash-verified

513};
514
515export 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

Callers 1

schema.tsFile · 0.85

Calls 8

updateMethod · 0.95
prepareOutFolderFunction · 0.90
applySqliteSnapshotsDiffFunction · 0.90
squashSqliteSchemeFunction · 0.90
writeResultFunction · 0.90
connectToSQLiteFunction · 0.85
relationsToTypeScriptFunction · 0.85
joinFunction · 0.85

Tested by

no test coverage detected