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

createJoin() — drizzle-orm Function Reference

Architecture documentation for the createJoin() function in update.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  e4cd8719_9e69_dac2_e0b4_723ac029103b["createJoin()"]
  40e4076c_05d5_c280_7940_f08e5d3868d9["GelUpdateBase"]
  e4cd8719_9e69_dac2_e0b4_723ac029103b -->|defined in| 40e4076c_05d5_c280_7940_f08e5d3868d9
  3238fc0a_15c3_86c0_b18e_e49c5f970a96["getTableLikeFields()"]
  e4cd8719_9e69_dac2_e0b4_723ac029103b -->|calls| 3238fc0a_15c3_86c0_b18e_e49c5f970a96
  style e4cd8719_9e69_dac2_e0b4_723ac029103b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/gel-core/query-builders/update.ts lines 365–425

	private createJoin<TJoinType extends JoinType>(
		joinType: TJoinType,
	): GelUpdateJoinFn<this, TDynamic, TJoinType> {
		return ((
			table: GelTable | Subquery | GelViewBase | SQL,
			on: ((updateTable: TTable, from: TFrom) => SQL | undefined) | SQL | undefined,
		) => {
			const tableName = getTableLikeName(table);

			if (typeof tableName === 'string' && this.config.joins.some((join) => join.alias === tableName)) {
				throw new Error(`Alias "${tableName}" is already used in this query`);
			}

			if (typeof on === 'function') {
				const from = this.config.from && !is(this.config.from, SQL)
					? this.getTableLikeFields(this.config.from)
					: undefined;
				on = on(
					new Proxy(
						this.config.table[Table.Symbol.Columns],
						new SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),
					) as any,
					from && new Proxy(
						from,
						new SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),
					) as any,
				);
			}

			this.config.joins.push({ on, table, joinType, alias: tableName });

			if (typeof tableName === 'string') {
				switch (joinType) {
					case 'left': {
						this.joinsNotNullableMap[tableName] = false;
						break;
					}
					case 'right': {
						this.joinsNotNullableMap = Object.fromEntries(
							Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]),
						);
						this.joinsNotNullableMap[tableName] = true;
						break;
					}
					case 'inner': {
						this.joinsNotNullableMap[tableName] = true;
						break;
					}
					case 'full': {
						this.joinsNotNullableMap = Object.fromEntries(
							Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]),
						);
						this.joinsNotNullableMap[tableName] = false;
						break;
					}
				}
			}

			return this as any;
		}) as any;
	}

Domain

Subdomains

Frequently Asked Questions

What does createJoin() do?
createJoin() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/gel-core/query-builders/update.ts.
Where is createJoin() defined?
createJoin() is defined in drizzle-orm/src/gel-core/query-builders/update.ts at line 365.
What does createJoin() call?
createJoin() calls 1 function(s): getTableLikeFields.

Analyze Your Own Codebase

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

Try Supermodel Free