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

convert() — drizzle-orm Function Reference

Architecture documentation for the convert() function in sqlgenerator.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  9bda6163_ef7b_3f92_031e_0bd4435fc770["convert()"]
  cc230e3a_5094_8f78_f677_c2c8e9f510a0["LibSQLCreateForeignKeyConvertor"]
  9bda6163_ef7b_3f92_031e_0bd4435fc770 -->|defined in| cc230e3a_5094_8f78_f677_c2c8e9f510a0
  style 9bda6163_ef7b_3f92_031e_0bd4435fc770 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/sqlgenerator.ts lines 3377–3399

	convert(
		statement: JsonCreateReferenceStatement,
		json2?: SQLiteSchemaSquashed,
		action?: 'push',
	): string {
		const { columnsFrom, columnsTo, tableFrom, onDelete, onUpdate, tableTo } = action === 'push'
			? SQLiteSquasher.unsquashPushFK(statement.data)
			: SQLiteSquasher.unsquashFK(statement.data);
		const { columnDefault, columnNotNull, columnType } = statement;

		const onDeleteStatement = onDelete ? ` ON DELETE ${onDelete}` : '';
		const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : '';
		const columnsDefaultValue = columnDefault
			? ` DEFAULT ${columnDefault}`
			: '';
		const columnNotNullValue = columnNotNull ? ` NOT NULL` : '';
		const columnTypeValue = columnType ? ` ${columnType}` : '';

		const columnFrom = columnsFrom[0];
		const columnTo = columnsTo[0];

		return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue} REFERENCES ${tableTo}(${columnTo})${onDeleteStatement}${onUpdateStatement};`;
	}

Domain

Subdomains

Frequently Asked Questions

What does convert() do?
convert() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/sqlgenerator.ts.
Where is convert() defined?
convert() is defined in drizzle-kit/src/sqlgenerator.ts at line 3377.

Analyze Your Own Codebase

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

Try Supermodel Free