PgRelationalQuery Class — drizzle-orm Architecture
Architecture documentation for the PgRelationalQuery class in query.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 1020167a_b256_b43e_d8d1_71bd293c5e55["PgRelationalQuery"] cb792d01_598c_043a_5de1_379e203f46ee["query.ts"] 1020167a_b256_b43e_d8d1_71bd293c5e55 -->|defined in| cb792d01_598c_043a_5de1_379e203f46ee 2f83ff2d_5e96_48be_37b3_60b46a1964ac["constructor()"] 1020167a_b256_b43e_d8d1_71bd293c5e55 -->|method| 2f83ff2d_5e96_48be_37b3_60b46a1964ac 7200bba7_cfc4_9235_f1c5_3ba5546808f9["_prepare()"] 1020167a_b256_b43e_d8d1_71bd293c5e55 -->|method| 7200bba7_cfc4_9235_f1c5_3ba5546808f9 9b49171c_da6e_db57_2dda_9dafb6091f73["prepare()"] 1020167a_b256_b43e_d8d1_71bd293c5e55 -->|method| 9b49171c_da6e_db57_2dda_9dafb6091f73 87ccc279_3432_ddf1_9cef_b0dfb006de8d["_getQuery()"] 1020167a_b256_b43e_d8d1_71bd293c5e55 -->|method| 87ccc279_3432_ddf1_9cef_b0dfb006de8d 841a8612_db2f_8c4a_7be2_05ccf6e288e7["getSQL()"] 1020167a_b256_b43e_d8d1_71bd293c5e55 -->|method| 841a8612_db2f_8c4a_7be2_05ccf6e288e7 2b0b24a6_e5d7_1385_86d1_be24fe87feb9["_toSQL()"] 1020167a_b256_b43e_d8d1_71bd293c5e55 -->|method| 2b0b24a6_e5d7_1385_86d1_be24fe87feb9 cbf38a7d_63b9_dd7a_2b52_7a988094d6d7["toSQL()"] 1020167a_b256_b43e_d8d1_71bd293c5e55 -->|method| cbf38a7d_63b9_dd7a_2b52_7a988094d6d7 0ae32bce_be94_4cb4_9a25_8a9b56eb2ae9["setToken()"] 1020167a_b256_b43e_d8d1_71bd293c5e55 -->|method| 0ae32bce_be94_4cb4_9a25_8a9b56eb2ae9 5dd36ef9_8a2d_412a_8ed0_0808a622fa34["execute()"] 1020167a_b256_b43e_d8d1_71bd293c5e55 -->|method| 5dd36ef9_8a2d_412a_8ed0_0808a622fa34
Relationship Graph
Source Code
drizzle-orm/src/pg-core/query-builders/query.ts lines 65–157
export class PgRelationalQuery<TResult> extends QueryPromise<TResult>
implements RunnableQuery<TResult, 'pg'>, SQLWrapper
{
static override readonly [entityKind]: string = 'PgRelationalQuery';
declare readonly _: {
readonly dialect: 'pg';
readonly result: TResult;
};
constructor(
private fullSchema: Record<string, unknown>,
private schema: TablesRelationalConfig,
private tableNamesMap: Record<string, string>,
private table: PgTable,
private tableConfig: TableRelationalConfig,
private dialect: PgDialect,
private session: PgSession,
private config: DBQueryConfig<'many', true> | true,
private mode: 'many' | 'first',
) {
super();
}
/** @internal */
_prepare(name?: string): PgPreparedQuery<PreparedQueryConfig & { execute: TResult }> {
return tracer.startActiveSpan('drizzle.prepareQuery', () => {
const { query, builtQuery } = this._toSQL();
return this.session.prepareQuery<PreparedQueryConfig & { execute: TResult }>(
builtQuery,
undefined,
name,
true,
(rawRows, mapColumnValue) => {
const rows = rawRows.map((row) =>
mapRelationalRow(this.schema, this.tableConfig, row, query.selection, mapColumnValue)
);
if (this.mode === 'first') {
return rows[0] as TResult;
}
return rows as TResult;
},
);
});
}
prepare(name: string): PgPreparedQuery<PreparedQueryConfig & { execute: TResult }> {
return this._prepare(name);
}
private _getQuery() {
return this.dialect.buildRelationalQueryWithoutPK({
fullSchema: this.fullSchema,
schema: this.schema,
tableNamesMap: this.tableNamesMap,
table: this.table,
tableConfig: this.tableConfig,
queryConfig: this.config,
tableAlias: this.tableConfig.tsName,
});
}
/** @internal */
getSQL(): SQL {
return this._getQuery().sql as SQL;
}
private _toSQL(): { query: BuildRelationalQueryResult; builtQuery: QueryWithTypings } {
const query = this._getQuery();
const builtQuery = this.dialect.sqlToQuery(query.sql as SQL);
return { query, builtQuery };
}
toSQL(): Query {
return this._toSQL().builtQuery;
}
private authToken?: NeonAuthToken;
Domain
Source
Frequently Asked Questions
What is the PgRelationalQuery class?
PgRelationalQuery is a class in the drizzle-orm codebase, defined in drizzle-orm/src/pg-core/query-builders/query.ts.
Where is PgRelationalQuery defined?
PgRelationalQuery is defined in drizzle-orm/src/pg-core/query-builders/query.ts at line 65.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free