Home / Function/ introspectMySQLToFile() — drizzle-orm Function Reference

introspectMySQLToFile() — drizzle-orm Function Reference

Architecture documentation for the introspectMySQLToFile() function in schemaDiffer.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  427d2d10_aac8_370d_cdb2_48b33e8401d1["introspectMySQLToFile()"]
  fb6b4a65_030b_ce6b_df0d_2be21adcd2b3["schemaDiffer.ts"]
  427d2d10_aac8_370d_cdb2_48b33e8401d1 -->|defined in| fb6b4a65_030b_ce6b_df0d_2be21adcd2b3
  54ca5813_630b_5da2_847e_de001e848a8c["applyMySqlDiffs()"]
  427d2d10_aac8_370d_cdb2_48b33e8401d1 -->|calls| 54ca5813_630b_5da2_847e_de001e848a8c
  fd1b2256_62ed_ec7e_c677_9d8cbf56136b["testTablesResolver()"]
  427d2d10_aac8_370d_cdb2_48b33e8401d1 -->|calls| fd1b2256_62ed_ec7e_c677_9d8cbf56136b
  96edd91d_9f30_fc37_cbd3_7c1229315b14["testColumnsResolver()"]
  427d2d10_aac8_370d_cdb2_48b33e8401d1 -->|calls| 96edd91d_9f30_fc37_cbd3_7c1229315b14
  7e811756_c9c2_7d90_53fe_72a918318b67["testViewsResolverMySql()"]
  427d2d10_aac8_370d_cdb2_48b33e8401d1 -->|calls| 7e811756_c9c2_7d90_53fe_72a918318b67
  style 427d2d10_aac8_370d_cdb2_48b33e8401d1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/tests/schemaDiffer.ts lines 2434–2517

export const introspectMySQLToFile = async (
	client: Connection,
	initSchema: MysqlSchema,
	testName: string,
	schema: string,
	casing?: CasingType | undefined,
) => {
	// put in db
	const { sqlStatements } = await applyMySqlDiffs(initSchema, casing);
	for (const st of sqlStatements) {
		await client.query(st);
	}

	// introspect to schema
	const introspectedSchema = await fromMySqlDatabase(
		{
			query: async (sql: string, params?: any[] | undefined) => {
				const res = await client.execute(sql, params);
				return res[0] as any;
			},
		},
		schema,
	);

	const { version: initV, dialect: initD, ...initRest } = introspectedSchema;

	const initSch = {
		version: '5',
		dialect: 'mysql',
		id: '0',
		prevId: '0',
		...initRest,
	} as const;

	const initSn = squashMysqlScheme(initSch);
	const validatedCur = mysqlSchema.parse(initSch);

	const file = schemaToTypeScriptMySQL(introspectedSchema, 'camel');

	fs.writeFileSync(`tests/introspect/mysql/${testName}.ts`, file.file);

	const response = await prepareFromMySqlImports([
		`tests/introspect/mysql/${testName}.ts`,
	]);

	const afterFileImports = generateMySqlSnapshot(
		response.tables,
		response.views,
		casing,
	);

	const { version: v2, dialect: d2, ...rest2 } = afterFileImports;

	const sch2 = {
		version: '5',
		dialect: 'mysql',
		id: '0',
		prevId: '0',
		...rest2,
	} as const;

	const sn2AfterIm = squashMysqlScheme(sch2);
	const validatedCurAfterImport = mysqlSchema.parse(sch2);

	const {
		sqlStatements: afterFileSqlStatements,
		statements: afterFileStatements,
	} = await applyMysqlSnapshotsDiff(
		sn2AfterIm,
		initSn,
		testTablesResolver(new Set()),
		testColumnsResolver(new Set()),
		testViewsResolverMySql(new Set()),
		validatedCurAfterImport,
		validatedCur,
	);

	fs.rmSync(`tests/introspect/mysql/${testName}.ts`);

	return {
		sqlStatements: afterFileSqlStatements,

Domain

Subdomains

Frequently Asked Questions

What does introspectMySQLToFile() do?
introspectMySQLToFile() is a function in the drizzle-orm codebase, defined in drizzle-kit/tests/schemaDiffer.ts.
Where is introspectMySQLToFile() defined?
introspectMySQLToFile() is defined in drizzle-kit/tests/schemaDiffer.ts at line 2434.
What does introspectMySQLToFile() call?
introspectMySQLToFile() calls 4 function(s): applyMySqlDiffs, testColumnsResolver, testTablesResolver, testViewsResolverMySql.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free