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

mapRelationalRow() — drizzle-orm Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  df653029_504d_b816_43f6_f1fa1183d155["mapRelationalRow()"]
  2f47d090_425d_2e56_2395_4c4d912316f0["relations.ts"]
  df653029_504d_b816_43f6_f1fa1183d155 -->|defined in| 2f47d090_425d_2e56_2395_4c4d912316f0
  c020d230_75a2_3639_d9a6_35f2ba7fd5bc["is()"]
  df653029_504d_b816_43f6_f1fa1183d155 -->|calls| c020d230_75a2_3639_d9a6_35f2ba7fd5bc
  style df653029_504d_b816_43f6_f1fa1183d155 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/relations.ts lines 666–725

export function mapRelationalRow(
	tablesConfig: TablesRelationalConfig,
	tableConfig: TableRelationalConfig,
	row: unknown[],
	buildQueryResultSelection: BuildRelationalQueryResult['selection'],
	mapColumnValue: (value: unknown) => unknown = (value) => value,
): Record<string, unknown> {
	const result: Record<string, unknown> = {};

	for (
		const [
			selectionItemIndex,
			selectionItem,
		] of buildQueryResultSelection.entries()
	) {
		if (selectionItem.isJson) {
			const relation = tableConfig.relations[selectionItem.tsKey]!;
			const rawSubRows = row[selectionItemIndex] as
				| unknown[]
				| null
				| [null]
				| string;
			const subRows = typeof rawSubRows === 'string'
				? (JSON.parse(rawSubRows) as unknown[])
				: rawSubRows;
			result[selectionItem.tsKey] = is(relation, One)
				? subRows
					&& mapRelationalRow(
						tablesConfig,
						tablesConfig[selectionItem.relationTableTsKey!]!,
						subRows,
						selectionItem.selection,
						mapColumnValue,
					)
				: (subRows as unknown[][]).map((subRow) =>
					mapRelationalRow(
						tablesConfig,
						tablesConfig[selectionItem.relationTableTsKey!]!,
						subRow,
						selectionItem.selection,
						mapColumnValue,
					)
				);
		} else {
			const value = mapColumnValue(row[selectionItemIndex]);
			const field = selectionItem.field!;
			let decoder;
			if (is(field, Column)) {
				decoder = field;
			} else if (is(field, SQL)) {
				decoder = field.decoder;
			} else {
				decoder = field.sql.decoder;
			}
			result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
		}
	}

	return result;
}

Domain

Subdomains

Calls

Frequently Asked Questions

What does mapRelationalRow() do?
mapRelationalRow() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/relations.ts.
Where is mapRelationalRow() defined?
mapRelationalRow() is defined in drizzle-orm/src/relations.ts at line 666.
What does mapRelationalRow() call?
mapRelationalRow() calls 1 function(s): is.

Analyze Your Own Codebase

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

Try Supermodel Free