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

createTableFKs() — drizzle-orm Function Reference

Architecture documentation for the createTableFKs() function in introspect-mysql.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  80a6bf84_feb5_5de0_735c_4c6a5accea61["createTableFKs()"]
  1198bdc6_ac5c_88c0_dda6_b8caf0f5d9fa["introspect-mysql.ts"]
  80a6bf84_feb5_5de0_735c_4c6a5accea61 -->|defined in| 1198bdc6_ac5c_88c0_dda6_b8caf0f5d9fa
  194539cf_d577_ab5e_4ea9_ec2fd5ee230b["schemaToTypeScript()"]
  194539cf_d577_ab5e_4ea9_ec2fd5ee230b -->|calls| 80a6bf84_feb5_5de0_735c_4c6a5accea61
  style 80a6bf84_feb5_5de0_735c_4c6a5accea61 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/introspect-mysql.ts lines 994–1030

const createTableFKs = (
	fks: ForeignKey[],
	casing: (value: string) => string,
): string => {
	let statement = '';

	fks.forEach((it) => {
		const isSelf = it.tableTo === it.tableFrom;
		const tableTo = isSelf ? 'table' : `${casing(it.tableTo)}`;
		statement += `\n\t`;
		statement += `foreignKey({\n`;
		statement += `\t\t\tcolumns: [${
			it.columnsFrom
				.map((i) => `table.${casing(i)}`)
				.join(', ')
		}],\n`;
		statement += `\t\t\tforeignColumns: [${
			it.columnsTo
				.map((i) => `${tableTo}.${casing(i)}`)
				.join(', ')
		}],\n`;
		statement += `\t\t\tname: "${it.name}"\n`;
		statement += `\t\t})`;

		statement += it.onUpdate && it.onUpdate !== 'no action'
			? `.onUpdate("${it.onUpdate}")`
			: '';

		statement += it.onDelete && it.onDelete !== 'no action'
			? `.onDelete("${it.onDelete}")`
			: '';

		statement += `,`;
	});

	return statement;
};

Domain

Subdomains

Frequently Asked Questions

What does createTableFKs() do?
createTableFKs() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/introspect-mysql.ts.
Where is createTableFKs() defined?
createTableFKs() is defined in drizzle-kit/src/introspect-mysql.ts at line 994.
What calls createTableFKs()?
createTableFKs() is called by 1 function(s): schemaToTypeScript.

Analyze Your Own Codebase

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

Try Supermodel Free