Home / Class/ PgSelectBase Class — drizzle-orm Architecture

PgSelectBase Class — drizzle-orm Architecture

Architecture documentation for the PgSelectBase class in select.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  e569e8e9_3ce1_66ee_59bb_3f6cc0bf0436["PgSelectBase"]
  50a440a3_419f_74a4_a0ef_a8f58a685eb0["select.ts"]
  e569e8e9_3ce1_66ee_59bb_3f6cc0bf0436 -->|defined in| 50a440a3_419f_74a4_a0ef_a8f58a685eb0
  8d79da65_eddc_3124_cae2_fd679f150555["_prepare()"]
  e569e8e9_3ce1_66ee_59bb_3f6cc0bf0436 -->|method| 8d79da65_eddc_3124_cae2_fd679f150555
  64444395_16ba_ad90_e78c_e1e77c34c940["prepare()"]
  e569e8e9_3ce1_66ee_59bb_3f6cc0bf0436 -->|method| 64444395_16ba_ad90_e78c_e1e77c34c940
  5427d23c_045d_3f37_94f1_b26a3f1a0736["setToken()"]
  e569e8e9_3ce1_66ee_59bb_3f6cc0bf0436 -->|method| 5427d23c_045d_3f37_94f1_b26a3f1a0736

Relationship Graph

Source Code

drizzle-orm/src/pg-core/query-builders/select.ts lines 1054–1123

export class PgSelectBase<
	TTableName extends string | undefined,
	TSelection extends ColumnsSelection,
	TSelectMode extends SelectMode,
	TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>
		: {},
	TDynamic extends boolean = false,
	TExcludedMethods extends string = never,
	TResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],
	TSelectedFields = BuildSubquerySelection<TSelection, TNullabilityMap>,
> extends PgSelectQueryBuilderBase<
	PgSelectHKT,
	TTableName,
	TSelection,
	TSelectMode,
	TNullabilityMap,
	TDynamic,
	TExcludedMethods,
	TResult,
	TSelectedFields
> implements RunnableQuery<TResult, 'pg'>, SQLWrapper {
	static override readonly [entityKind]: string = 'PgSelect';

	/** @internal */
	_prepare(name?: string): PgSelectPrepare<this> {
		const { session, config, dialect, joinsNotNullableMap, authToken, cacheConfig, usedTables } = this;
		if (!session) {
			throw new Error('Cannot execute a query on a query builder. Please use a database instance instead.');
		}

		const { fields } = config;

		return tracer.startActiveSpan('drizzle.prepareQuery', () => {
			const fieldsList = orderSelectedFields<PgColumn>(fields);
			const query = session.prepareQuery<
				PreparedQueryConfig & { execute: TResult }
			>(dialect.sqlToQuery(this.getSQL()), fieldsList, name, true, undefined, {
				type: 'select',
				tables: [...usedTables],
			}, cacheConfig);
			query.joinsNotNullableMap = joinsNotNullableMap;

			return query.setToken(authToken);
		});
	}

	/**
	 * Create a prepared statement for this query. This allows
	 * the database to remember this query for the given session
	 * and call it by name, rather than specifying the full query.
	 *
	 * {@link https://www.postgresql.org/docs/current/sql-prepare.html | Postgres prepare documentation}
	 */
	prepare(name: string): PgSelectPrepare<this> {
		return this._prepare(name);
	}

	private authToken?: NeonAuthToken;
	/** @internal */
	setToken(token?: NeonAuthToken) {
		this.authToken = token;
		return this;
	}

	execute: ReturnType<this['prepare']>['execute'] = (placeholderValues) => {
		return tracer.startActiveSpan('drizzle.operation', () => {
			return this._prepare().execute(placeholderValues, this.authToken);
		});
	};
}

Domain

Frequently Asked Questions

What is the PgSelectBase class?
PgSelectBase is a class in the drizzle-orm codebase, defined in drizzle-orm/src/pg-core/query-builders/select.ts.
Where is PgSelectBase defined?
PgSelectBase is defined in drizzle-orm/src/pg-core/query-builders/select.ts at line 1054.

Analyze Your Own Codebase

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

Try Supermodel Free