buildRelationalQueryWithoutPK() — drizzle-orm Function Reference
Architecture documentation for the buildRelationalQueryWithoutPK() function in dialect.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 4fe5b8c4_3d15_8881_602b_e044ec70f270["buildRelationalQueryWithoutPK()"] 3977a3fd_2f08_73b1_4df4_3d0fd1858514["PgDialect"] 4fe5b8c4_3d15_8881_602b_e044ec70f270 -->|defined in| 3977a3fd_2f08_73b1_4df4_3d0fd1858514 87ccc279_3432_ddf1_9cef_b0dfb006de8d["_getQuery()"] 87ccc279_3432_ddf1_9cef_b0dfb006de8d -->|calls| 4fe5b8c4_3d15_8881_602b_e044ec70f270 9a7f35b1_0b1e_f3ac_68cb_233ef6bc00a0["buildSelectQuery()"] 4fe5b8c4_3d15_8881_602b_e044ec70f270 -->|calls| 9a7f35b1_0b1e_f3ac_68cb_233ef6bc00a0 style 4fe5b8c4_3d15_8881_602b_e044ec70f270 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-orm/src/pg-core/dialect.ts lines 1150–1444
buildRelationalQueryWithoutPK({
fullSchema,
schema,
tableNamesMap,
table,
tableConfig,
queryConfig: config,
tableAlias,
nestedQueryRelation,
joinOn,
}: {
fullSchema: Record<string, unknown>;
schema: TablesRelationalConfig;
tableNamesMap: Record<string, string>;
table: PgTable;
tableConfig: TableRelationalConfig;
queryConfig: true | DBQueryConfig<'many', true>;
tableAlias: string;
nestedQueryRelation?: Relation;
joinOn?: SQL;
}): BuildRelationalQueryResult<PgTable, PgColumn> {
let selection: BuildRelationalQueryResult<PgTable, PgColumn>['selection'] = [];
let limit, offset, orderBy: NonNullable<PgSelectConfig['orderBy']> = [], where;
const joins: PgSelectJoinConfig[] = [];
if (config === true) {
const selectionEntries = Object.entries(tableConfig.columns);
selection = selectionEntries.map((
[key, value],
) => ({
dbKey: value.name,
tsKey: key,
field: aliasedTableColumn(value as PgColumn, tableAlias),
relationTableTsKey: undefined,
isJson: false,
selection: [],
}));
} else {
const aliasedColumns = Object.fromEntries(
Object.entries(tableConfig.columns).map((
[key, value],
) => [key, aliasedTableColumn(value, tableAlias)]),
);
if (config.where) {
const whereSql = typeof config.where === 'function'
? config.where(aliasedColumns, getOperators())
: config.where;
where = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);
}
const fieldsSelection: { tsKey: string; value: PgColumn | SQL.Aliased }[] = [];
let selectedColumns: string[] = [];
// Figure out which columns to select
if (config.columns) {
let isIncludeMode = false;
for (const [field, value] of Object.entries(config.columns)) {
if (value === undefined) {
continue;
}
if (field in tableConfig.columns) {
if (!isIncludeMode && value === true) {
isIncludeMode = true;
}
selectedColumns.push(field);
}
}
if (selectedColumns.length > 0) {
selectedColumns = isIncludeMode
? selectedColumns.filter((c) => config.columns?.[c] === true)
: Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));
}
} else {
// Select all columns if selection is not specified
selectedColumns = Object.keys(tableConfig.columns);
}
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does buildRelationalQueryWithoutPK() do?
buildRelationalQueryWithoutPK() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/pg-core/dialect.ts.
Where is buildRelationalQueryWithoutPK() defined?
buildRelationalQueryWithoutPK() is defined in drizzle-orm/src/pg-core/dialect.ts at line 1150.
What does buildRelationalQueryWithoutPK() call?
buildRelationalQueryWithoutPK() calls 1 function(s): buildSelectQuery.
What calls buildRelationalQueryWithoutPK()?
buildRelationalQueryWithoutPK() is called by 1 function(s): _getQuery.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free