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

libSQLCombineStatements() — drizzle-orm Function Reference

Architecture documentation for the libSQLCombineStatements() function in statementCombiner.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  7185395a_8db7_95fd_888a_bc6d13893d75["libSQLCombineStatements()"]
  21a395af_9564_2dbd_9ea9_060ad50ee7a0["statementCombiner.ts"]
  7185395a_8db7_95fd_888a_bc6d13893d75 -->|defined in| 21a395af_9564_2dbd_9ea9_060ad50ee7a0
  55569cde_7638_9cfc_9dcd_34636d975ec3["applyLibSQLSnapshotsDiff()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| 7185395a_8db7_95fd_888a_bc6d13893d75
  02eb8e63_cc1f_ad01_411f_c75b81563b47["prepareLibSQLRecreateTable()"]
  7185395a_8db7_95fd_888a_bc6d13893d75 -->|calls| 02eb8e63_cc1f_ad01_411f_c75b81563b47
  style 7185395a_8db7_95fd_888a_bc6d13893d75 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/statementCombiner.ts lines 76–303

export const libSQLCombineStatements = (
	statements: JsonStatement[],
	json2: SQLiteSchemaSquashed,
	action?: 'push',
) => {
	// const tablesContext: Record<string, string[]> = {};
	const newStatements: Record<string, JsonStatement[]> = {};
	for (const statement of statements) {
		if (
			statement.type === 'alter_table_alter_column_drop_autoincrement'
			|| statement.type === 'alter_table_alter_column_set_autoincrement'
			|| statement.type === 'alter_table_alter_column_drop_pk'
			|| statement.type === 'alter_table_alter_column_set_pk'
			|| statement.type === 'create_composite_pk'
			|| statement.type === 'alter_composite_pk'
			|| statement.type === 'delete_composite_pk'
			|| statement.type === 'create_check_constraint'
			|| statement.type === 'delete_check_constraint'
		) {
			const tableName = statement.tableName;

			const statementsForTable = newStatements[tableName];

			if (!statementsForTable) {
				newStatements[tableName] = prepareLibSQLRecreateTable(json2.tables[tableName], action);

				continue;
			}

			if (!statementsForTable.some(({ type }) => type === 'recreate_table')) {
				const wasRename = statementsForTable.some(({ type }) => type === 'rename_table');
				const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName], action);

				if (wasRename) {
					newStatements[tableName].push(...preparedStatements);
				} else {
					newStatements[tableName] = preparedStatements;
				}

				continue;
			}

			continue;
		}

		if (
			statement.type === 'alter_table_alter_column_set_type'
			|| statement.type === 'alter_table_alter_column_drop_notnull'
			|| statement.type === 'alter_table_alter_column_set_notnull'
			|| statement.type === 'alter_table_alter_column_set_default'
			|| statement.type === 'alter_table_alter_column_drop_default'
		) {
			const { tableName, columnName, columnPk } = statement;

			const columnIsPartOfForeignKey = Object.values(
				json2.tables[tableName].foreignKeys,
			).some((it) => {
				const unsquashFk = action === 'push' ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it);

				return (
					unsquashFk.columnsFrom.includes(columnName)
				);
			});

			const statementsForTable = newStatements[tableName];

			if (
				!statementsForTable && (columnIsPartOfForeignKey || columnPk)
			) {
				newStatements[tableName] = prepareLibSQLRecreateTable(json2.tables[tableName], action);
				continue;
			}

			if (
				statementsForTable && (columnIsPartOfForeignKey || columnPk)
			) {
				if (!statementsForTable.some(({ type }) => type === 'recreate_table')) {
					const wasRename = statementsForTable.some(({ type }) => type === 'rename_table');
					const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName], action);

					if (wasRename) {

Domain

Subdomains

Frequently Asked Questions

What does libSQLCombineStatements() do?
libSQLCombineStatements() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/statementCombiner.ts.
Where is libSQLCombineStatements() defined?
libSQLCombineStatements() is defined in drizzle-kit/src/statementCombiner.ts at line 76.
What does libSQLCombineStatements() call?
libSQLCombineStatements() calls 1 function(s): prepareLibSQLRecreateTable.
What calls libSQLCombineStatements()?
libSQLCombineStatements() is called by 1 function(s): applyLibSQLSnapshotsDiff.

Analyze Your Own Codebase

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

Try Supermodel Free