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

as() — drizzle-orm Function Reference

Architecture documentation for the as() function in view.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  5a7db7a7_5a13_75b6_6d80_3e1cceea0ee2["as()"]
  6ca59ca1_2408_7f86_2c07_ceb7bbc97289["ViewBuilder"]
  5a7db7a7_5a13_75b6_6d80_3e1cceea0ee2 -->|defined in| 6ca59ca1_2408_7f86_2c07_ceb7bbc97289
  style 5a7db7a7_5a13_75b6_6d80_3e1cceea0ee2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/pg-core/view.ts lines 47–72

	as<TSelectedFields extends ColumnsSelection>(
		qb: TypedQueryBuilder<TSelectedFields> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelectedFields>),
	): PgViewWithSelection<TName, false, AddAliasToSelection<TSelectedFields, TName, 'pg'>> {
		if (typeof qb === 'function') {
			qb = qb(new QueryBuilder());
		}
		const selectionProxy = new SelectionProxyHandler<TSelectedFields>({
			alias: this.name,
			sqlBehavior: 'error',
			sqlAliasedBehavior: 'alias',
			replaceOriginalName: true,
		});
		const aliasedSelection = new Proxy(qb.getSelectedFields(), selectionProxy);
		return new Proxy(
			new PgView({
				pgConfig: this.config,
				config: {
					name: this.name,
					schema: this.schema,
					selectedFields: aliasedSelection,
					query: qb.getSQL().inlineParams(),
				},
			}),
			selectionProxy as any,
		) as PgViewWithSelection<TName, false, AddAliasToSelection<TSelectedFields, TName, 'pg'>>;
	}

Domain

Subdomains

Frequently Asked Questions

What does as() do?
as() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/pg-core/view.ts.
Where is as() defined?
as() is defined in drizzle-orm/src/pg-core/view.ts at line 47.

Analyze Your Own Codebase

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

Try Supermodel Free