Home / File/ selection-proxy.ts — drizzle-orm Source File

selection-proxy.ts — drizzle-orm Source File

Architecture documentation for selection-proxy.ts, a typescript file in the drizzle-orm codebase. 13 imports, 0 dependents.

File typescript DrizzleORM DatabaseDrivers 13 imports 1 classes

Entity Profile

Dependency Diagram

graph LR
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb["selection-proxy.ts"]
  ab181952_5759_c0bf_aeab_f255a140fe2a["alias.ts"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> ab181952_5759_c0bf_aeab_f255a140fe2a
  15305ab6_27cf_e44a_11a3_0e2177d768f3["ColumnAliasProxyHandler"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> 15305ab6_27cf_e44a_11a3_0e2177d768f3
  b4991e83_4bea_3a01_aeb0_ab00b5e6b779["TableAliasProxyHandler"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> b4991e83_4bea_3a01_aeb0_ab00b5e6b779
  7bd0ba6a_93b0_0df7_7f87_d1a726b246cb["column.ts"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> 7bd0ba6a_93b0_0df7_7f87_d1a726b246cb
  48bb4797_1254_752d_d782_521f09c1a1d5["Column"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> 48bb4797_1254_752d_d782_521f09c1a1d5
  bc6d807f_7198_da43_c1e6_911af80c80ee["entity.ts"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> bc6d807f_7198_da43_c1e6_911af80c80ee
  c020d230_75a2_3639_d9a6_35f2ba7fd5bc["is"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> c020d230_75a2_3639_d9a6_35f2ba7fd5bc
  99347ab2_b1a1_faf4_e37c_7643e4b2eb8a["sql.ts"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> 99347ab2_b1a1_faf4_e37c_7643e4b2eb8a
  2361fb30_407d_7604_384a_a24acc5652f6["SQL"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> 2361fb30_407d_7604_384a_a24acc5652f6
  562ff959_f5c2_ad28_16c7_59f4a572a158["subquery.ts"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> 562ff959_f5c2_ad28_16c7_59f4a572a158
  9a5700de_3ec1_7ca6_7e10_7c5ff98bdce2["Subquery"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> 9a5700de_3ec1_7ca6_7e10_7c5ff98bdce2
  20acd966_42f6_0fd1_750c_0e0232a2019e["Subquery"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> 20acd966_42f6_0fd1_750c_0e0232a2019e
  0d9c6746_ab9a_92ca_2e6a_987b95f91630["view-common.ts"]
  a54a11d6_4422_4e60_3d09_6c04afd8f1eb --> 0d9c6746_ab9a_92ca_2e6a_987b95f91630
  style a54a11d6_4422_4e60_3d09_6c04afd8f1eb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { ColumnAliasProxyHandler, TableAliasProxyHandler } from './alias.ts';
import { Column } from './column.ts';
import { entityKind, is } from './entity.ts';
import { SQL, View } from './sql/sql.ts';
import { Subquery } from './subquery.ts';
import { ViewBaseConfig } from './view-common.ts';

export class SelectionProxyHandler<T extends Subquery | Record<string, unknown> | View>
	implements ProxyHandler<Subquery | Record<string, unknown> | View>
{
	static readonly [entityKind]: string = 'SelectionProxyHandler';

	private config: {
		/**
		 * Table alias for the columns
		 */
		alias?: string;
		/**
		 * What to do when a field is an instance of `SQL.Aliased` and it's not a selection field (from a subquery)
		 *
		 * `sql` - return the underlying SQL expression
		 *
		 * `alias` - return the field alias
		 */
		sqlAliasedBehavior: 'sql' | 'alias';
		/**
		 * What to do when a field is an instance of `SQL` and it doesn't have an alias declared
		 *
		 * `sql` - return the underlying SQL expression
		 *
		 * `error` - return a DrizzleTypeError on type level and throw an error on runtime
		 */
		sqlBehavior: 'sql' | 'error';

		/**
		 * Whether to replace the original name of the column with the alias
		 * Should be set to `true` for views creation
		 * @default false
		 */
		replaceOriginalName?: boolean;
	};

	constructor(config: SelectionProxyHandler<T>['config']) {
		this.config = { ...config };
	}

	get(subquery: T, prop: string | symbol): any {
		if (prop === '_') {
			return {
				...subquery['_' as keyof typeof subquery],
				selectedFields: new Proxy(
					(subquery as Subquery)._.selectedFields,
					this as ProxyHandler<Record<string, unknown>>,
				),
			};
		}

		if (prop === ViewBaseConfig) {
			return {
				...subquery[ViewBaseConfig as keyof typeof subquery],
// ... (62 more lines)

Domain

Subdomains

Frequently Asked Questions

What does selection-proxy.ts do?
selection-proxy.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, DatabaseDrivers subdomain.
What does selection-proxy.ts depend on?
selection-proxy.ts imports 13 module(s): Column, ColumnAliasProxyHandler, SQL, Subquery, Subquery, TableAliasProxyHandler, alias.ts, column.ts, and 5 more.
Where is selection-proxy.ts in the architecture?
selection-proxy.ts is located at drizzle-orm/src/selection-proxy.ts (domain: DrizzleORM, subdomain: DatabaseDrivers, directory: drizzle-orm/src).

Analyze Your Own Codebase

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

Try Supermodel Free