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

diffColumns() — drizzle-orm Function Reference

Architecture documentation for the diffColumns() function in jsonDiffer.js from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  9e8ab4fa_ee1f_a20f_8211_19013f210efc["diffColumns()"]
  42cd5bcb_caa4_6b61_11ea_da1b767eeadd["jsonDiffer.js"]
  9e8ab4fa_ee1f_a20f_8211_19013f210efc -->|defined in| 42cd5bcb_caa4_6b61_11ea_da1b767eeadd
  c7a398db_43c9_7771_09b7_73bc09e703e8["applyPgSnapshotsDiff()"]
  c7a398db_43c9_7771_09b7_73bc09e703e8 -->|calls| 9e8ab4fa_ee1f_a20f_8211_19013f210efc
  a5972ffc_ff1b_9523_2495_5373af710e65["applyMysqlSnapshotsDiff()"]
  a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| 9e8ab4fa_ee1f_a20f_8211_19013f210efc
  d4992b27_bf78_8099_5134_750cef1c518c["applySingleStoreSnapshotsDiff()"]
  d4992b27_bf78_8099_5134_750cef1c518c -->|calls| 9e8ab4fa_ee1f_a20f_8211_19013f210efc
  d9097b7e_1e27_d29f_7732_f2fa1447f2b8["applySqliteSnapshotsDiff()"]
  d9097b7e_1e27_d29f_7732_f2fa1447f2b8 -->|calls| 9e8ab4fa_ee1f_a20f_8211_19013f210efc
  55569cde_7638_9cfc_9dcd_34636d975ec3["applyLibSQLSnapshotsDiff()"]
  55569cde_7638_9cfc_9dcd_34636d975ec3 -->|calls| 9e8ab4fa_ee1f_a20f_8211_19013f210efc
  style 9e8ab4fa_ee1f_a20f_8211_19013f210efc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/jsonDiffer.js lines 122–163

export function diffColumns(left, right) {
	left = JSON.parse(JSON.stringify(left));
	right = JSON.parse(JSON.stringify(right));
	const result = diff(left, right) ?? {};

	const alteredTables = Object.fromEntries(
		Object.entries(result)
			.filter((it) => {
				return !(it[0].includes('__added') || it[0].includes('__deleted'));
			})
			.map((tableEntry) => {
				// const entry = { name: it, ...result[it] }
				const deletedColumns = Object.entries(tableEntry[1].columns ?? {})
					.filter((it) => {
						return it[0].endsWith('__deleted');
					})
					.map((it) => {
						return it[1];
					});

				const addedColumns = Object.entries(tableEntry[1].columns ?? {})
					.filter((it) => {
						return it[0].endsWith('__added');
					})
					.map((it) => {
						return it[1];
					});

				tableEntry[1].columns = {
					added: addedColumns,
					deleted: deletedColumns,
				};
				const table = left[tableEntry[0]];
				return [
					tableEntry[0],
					{ name: table.name, schema: table.schema, ...tableEntry[1] },
				];
			}),
	);

	return alteredTables;
}

Domain

Subdomains

Frequently Asked Questions

What does diffColumns() do?
diffColumns() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/jsonDiffer.js.
Where is diffColumns() defined?
diffColumns() is defined in drizzle-kit/src/jsonDiffer.js at line 122.
What calls diffColumns()?
diffColumns() is called by 5 function(s): applyLibSQLSnapshotsDiff, applyMysqlSnapshotsDiff, applyPgSnapshotsDiff, applySingleStoreSnapshotsDiff, applySqliteSnapshotsDiff.

Analyze Your Own Codebase

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

Try Supermodel Free