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

sqliteCombineStatements() — drizzle-orm Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  17594a40_df6d_dbbc_6d7a_c1e90069584f["sqliteCombineStatements()"]
  21a395af_9564_2dbd_9ea9_060ad50ee7a0["statementCombiner.ts"]
  17594a40_df6d_dbbc_6d7a_c1e90069584f -->|defined in| 21a395af_9564_2dbd_9ea9_060ad50ee7a0
  d9097b7e_1e27_d29f_7732_f2fa1447f2b8["applySqliteSnapshotsDiff()"]
  d9097b7e_1e27_d29f_7732_f2fa1447f2b8 -->|calls| 17594a40_df6d_dbbc_6d7a_c1e90069584f
  ee76d848_3a47_3ee3_65e2_2d2277c500b8["prepareSQLiteRecreateTable()"]
  17594a40_df6d_dbbc_6d7a_c1e90069584f -->|calls| ee76d848_3a47_3ee3_65e2_2d2277c500b8
  style 17594a40_df6d_dbbc_6d7a_c1e90069584f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/statementCombiner.ts lines 305–447

export const sqliteCombineStatements = (
	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_set_type'
			|| statement.type === 'alter_table_alter_column_set_default'
			|| statement.type === 'alter_table_alter_column_drop_default'
			|| statement.type === 'alter_table_alter_column_set_notnull'
			|| statement.type === 'alter_table_alter_column_drop_notnull'
			|| 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 === 'delete_reference'
			|| statement.type === 'alter_reference'
			|| statement.type === 'create_composite_pk'
			|| statement.type === 'alter_composite_pk'
			|| statement.type === 'delete_composite_pk'
			|| statement.type === 'create_unique_constraint'
			|| statement.type === 'delete_unique_constraint'
			|| statement.type === 'create_check_constraint'
			|| statement.type === 'delete_check_constraint'
		) {
			const tableName = statement.tableName;

			const statementsForTable = newStatements[tableName];

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

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

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

				continue;
			}

			continue;
		}

		if (statement.type === 'sqlite_alter_table_add_column' && statement.column.primaryKey) {
			const tableName = statement.tableName;

			const statementsForTable = newStatements[tableName];

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

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

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

				continue;
			}

			continue;
		}

		if (statement.type === 'create_reference') {
			const tableName = statement.tableName;

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free