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

from() — drizzle-orm Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  a5023dfe_0d40_5c1a_df0e_f502a87bd474["from()"]
  b296e4b6_6606_47f0_2ff5_671089ced410["GelSelectBuilder"]
  a5023dfe_0d40_5c1a_df0e_f502a87bd474 -->|defined in| b296e4b6_6606_47f0_2ff5_671089ced410
  style a5023dfe_0d40_5c1a_df0e_f502a87bd474 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/gel-core/query-builders/select.ts lines 107–144

	from<TFrom extends GelTable | Subquery | GelViewBase | SQL>(
		source: TFrom,
	): CreateGelSelectFromBuilderMode<
		TBuilderMode,
		GetSelectTableName<TFrom>,
		TSelection extends undefined ? GetSelectTableSelection<TFrom> : TSelection,
		TSelection extends undefined ? 'single' : 'partial'
	> {
		const isPartialSelect = !!this.fields;

		let fields: SelectedFields;
		if (this.fields) {
			fields = this.fields;
		} else if (is(source, Subquery)) {
			// This is required to use the proxy handler to get the correct field values from the subquery
			fields = Object.fromEntries(
				Object.keys(source._.selectedFields).map((
					key,
				) => [key, source[key as unknown as keyof typeof source] as unknown as SelectedFields[string]]),
			);
		} else if (is(source, GelViewBase)) {
			fields = source[ViewBaseConfig].selectedFields as SelectedFields;
		} else if (is(source, SQL)) {
			fields = {};
		} else {
			fields = getTableColumns<GelTable>(source);
		}

		return new GelSelectBase({
			table: source,
			fields,
			isPartialSelect,
			session: this.session,
			dialect: this.dialect,
			withList: this.withList,
			distinct: this.distinct,
		}) as any;
	}

Domain

Subdomains

Frequently Asked Questions

What does from() do?
from() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/gel-core/query-builders/select.ts.
Where is from() defined?
from() is defined in drizzle-orm/src/gel-core/query-builders/select.ts at line 107.

Analyze Your Own Codebase

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

Try Supermodel Free