Home / Class/ TableAliasProxyHandler Class — drizzle-orm Architecture

TableAliasProxyHandler Class — drizzle-orm Architecture

Architecture documentation for the TableAliasProxyHandler class in alias.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  b4991e83_4bea_3a01_aeb0_ab00b5e6b779["TableAliasProxyHandler"]
  ab181952_5759_c0bf_aeab_f255a140fe2a["alias.ts"]
  b4991e83_4bea_3a01_aeb0_ab00b5e6b779 -->|defined in| ab181952_5759_c0bf_aeab_f255a140fe2a
  ff41f5b7_8de8_e9c7_fad8_9ed4386e41f3["constructor()"]
  b4991e83_4bea_3a01_aeb0_ab00b5e6b779 -->|method| ff41f5b7_8de8_e9c7_fad8_9ed4386e41f3
  8e92df7f_f898_3f9a_f9be_9a9823f94a4f["get()"]
  b4991e83_4bea_3a01_aeb0_ab00b5e6b779 -->|method| 8e92df7f_f898_3f9a_f9be_9a9823f94a4f

Relationship Graph

Source Code

drizzle-orm/src/alias.ts lines 24–75

export class TableAliasProxyHandler<T extends Table | View> implements ProxyHandler<T> {
	static readonly [entityKind]: string = 'TableAliasProxyHandler';

	constructor(private alias: string, private replaceOriginalName: boolean) {}

	get(target: T, prop: string | symbol): any {
		if (prop === Table.Symbol.IsAlias) {
			return true;
		}

		if (prop === Table.Symbol.Name) {
			return this.alias;
		}

		if (this.replaceOriginalName && prop === Table.Symbol.OriginalName) {
			return this.alias;
		}

		if (prop === ViewBaseConfig) {
			return {
				...target[ViewBaseConfig as keyof typeof target],
				name: this.alias,
				isAlias: true,
			};
		}

		if (prop === Table.Symbol.Columns) {
			const columns = (target as Table)[Table.Symbol.Columns];
			if (!columns) {
				return columns;
			}

			const proxiedColumns: { [key: string]: any } = {};

			Object.keys(columns).map((key) => {
				proxiedColumns[key] = new Proxy(
					columns[key]!,
					new ColumnAliasProxyHandler(new Proxy(target, this)),
				);
			});

			return proxiedColumns;
		}

		const value = target[prop as keyof typeof target];
		if (is(value, Column)) {
			return new Proxy(value as AnyColumn, new ColumnAliasProxyHandler(new Proxy(target, this)));
		}

		return value;
	}
}

Domain

Frequently Asked Questions

What is the TableAliasProxyHandler class?
TableAliasProxyHandler is a class in the drizzle-orm codebase, defined in drizzle-orm/src/alias.ts.
Where is TableAliasProxyHandler defined?
TableAliasProxyHandler is defined in drizzle-orm/src/alias.ts at line 24.

Analyze Your Own Codebase

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

Try Supermodel Free