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

Function introspectPostgres

drizzle-kit/src/cli/commands/introspect.ts:55–179  ·  view source on GitHub ↗
(
	casing: Casing,
	out: string,
	breakpoints: boolean,
	credentials: PostgresCredentials,
	tablesFilter: string[],
	schemasFilter: string[],
	prefix: Prefix,
	entities: Entities,
)

Source from the content-addressed store, hash-verified

53} from './migrate';
54
55export const introspectPostgres = async (
56 casing: Casing,
57 out: string,
58 breakpoints: boolean,
59 credentials: PostgresCredentials,
60 tablesFilter: string[],
61 schemasFilter: string[],
62 prefix: Prefix,
63 entities: Entities,
64) => {
65 const { preparePostgresDB } = await import('../connections');
66 const db = await preparePostgresDB(credentials);
67
68 const matchers = tablesFilter.map((it) => {
69 return new Minimatch(it);
70 });
71
72 const filter = (tableName: string) => {
73 if (matchers.length === 0) return true;
74
75 let flags: boolean[] = [];
76
77 for (let matcher of matchers) {
78 if (matcher.negate) {
79 if (!matcher.match(tableName)) {
80 flags.push(false);
81 }
82 }
83
84 if (matcher.match(tableName)) {
85 flags.push(true);
86 }
87 }
88
89 if (flags.length > 0) {
90 return flags.every(Boolean);
91 }
92 return false;
93 };
94
95 const progress = new IntrospectProgress(true);
96
97 const res = await renderWithTask(
98 progress,
99 fromPostgresDatabase(
100 db,
101 filter,
102 schemasFilter,
103 entities,
104 (stage, count, status) => {
105 progress.update(stage, count, status);
106 },
107 ),
108 );
109
110 const schema = { id: originUUID, prevId: '', ...res } as PgSchema;
111 const ts = postgresSchemaToTypeScript(schema, casing);
112 const relationsTs = relationsToTypeScript(schema, casing);

Callers 1

schema.tsFile · 0.85

Calls 8

updateMethod · 0.95
prepareOutFolderFunction · 0.90
applyPgSnapshotsDiffFunction · 0.90
squashPgSchemeFunction · 0.90
writeResultFunction · 0.90
preparePostgresDBFunction · 0.85
relationsToTypeScriptFunction · 0.85
joinFunction · 0.85

Tested by

no test coverage detected