Home / File/ utils.ts — drizzle-orm Source File

utils.ts — drizzle-orm Source File

Architecture documentation for utils.ts, a typescript file in the drizzle-orm codebase. 19 imports, 5 dependents.

File typescript DrizzleORM DatabaseDrivers 19 imports 5 dependents 12 functions

Entity Profile

Dependency Diagram

graph LR
  99737bc3_a631_a054_9291_f966c791930f["utils.ts"]
  7d233f23_2ad0_1787_1add_b603646ee5a1["cache.ts"]
  99737bc3_a631_a054_9291_f966c791930f --> 7d233f23_2ad0_1787_1add_b603646ee5a1
  7bd0ba6a_93b0_0df7_7f87_d1a726b246cb["column.ts"]
  99737bc3_a631_a054_9291_f966c791930f --> 7bd0ba6a_93b0_0df7_7f87_d1a726b246cb
  48bb4797_1254_752d_d782_521f09c1a1d5["Column"]
  99737bc3_a631_a054_9291_f966c791930f --> 48bb4797_1254_752d_d782_521f09c1a1d5
  bc6d807f_7198_da43_c1e6_911af80c80ee["entity.ts"]
  99737bc3_a631_a054_9291_f966c791930f --> bc6d807f_7198_da43_c1e6_911af80c80ee
  c020d230_75a2_3639_d9a6_35f2ba7fd5bc["is"]
  99737bc3_a631_a054_9291_f966c791930f --> c020d230_75a2_3639_d9a6_35f2ba7fd5bc
  60da011b_729a_992e_0865_db2038e618a2["logger.ts"]
  99737bc3_a631_a054_9291_f966c791930f --> 60da011b_729a_992e_0865_db2038e618a2
  7664a866_a3c0_a860_d69f_58ff87a29d3b["operations.ts"]
  99737bc3_a631_a054_9291_f966c791930f --> 7664a866_a3c0_a860_d69f_58ff87a29d3b
  7e7f8434_4765_0a70_b7fa_d197dd2fa706["select.types.ts"]
  99737bc3_a631_a054_9291_f966c791930f --> 7e7f8434_4765_0a70_b7fa_d197dd2fa706
  99347ab2_b1a1_faf4_e37c_7643e4b2eb8a["sql.ts"]
  99737bc3_a631_a054_9291_f966c791930f --> 99347ab2_b1a1_faf4_e37c_7643e4b2eb8a
  d61f487a_d2dd_edf1_cf65_be62c407b136["Param"]
  99737bc3_a631_a054_9291_f966c791930f --> d61f487a_d2dd_edf1_cf65_be62c407b136
  2361fb30_407d_7604_384a_a24acc5652f6["SQL"]
  99737bc3_a631_a054_9291_f966c791930f --> 2361fb30_407d_7604_384a_a24acc5652f6
  562ff959_f5c2_ad28_16c7_59f4a572a158["subquery.ts"]
  99737bc3_a631_a054_9291_f966c791930f --> 562ff959_f5c2_ad28_16c7_59f4a572a158
  9a5700de_3ec1_7ca6_7e10_7c5ff98bdce2["Subquery"]
  99737bc3_a631_a054_9291_f966c791930f --> 9a5700de_3ec1_7ca6_7e10_7c5ff98bdce2
  20acd966_42f6_0fd1_750c_0e0232a2019e["Subquery"]
  99737bc3_a631_a054_9291_f966c791930f --> 20acd966_42f6_0fd1_750c_0e0232a2019e
  style 99737bc3_a631_a054_9291_f966c791930f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Cache } from './cache/core/cache.ts';
import type { AnyColumn } from './column.ts';
import { Column } from './column.ts';
import { is } from './entity.ts';
import type { Logger } from './logger.ts';
import type { SelectedFieldsOrdered } from './operations.ts';
import type { TableLike } from './query-builders/select.types.ts';
import { Param, SQL, View } from './sql/sql.ts';
import type { DriverValueDecoder } from './sql/sql.ts';
import { Subquery } from './subquery.ts';
import { getTableName, Table } from './table.ts';
import { ViewBaseConfig } from './view-common.ts';

/** @internal */
export function mapResultRow<TResult>(
	columns: SelectedFieldsOrdered<AnyColumn>,
	row: unknown[],
	joinsNotNullableMap: Record<string, boolean> | undefined,
): TResult {
	// Key -> nested object key, value -> table name if all fields in the nested object are from the same table, false otherwise
	const nullifyMap: Record<string, string | false> = {};

	const result = columns.reduce<Record<string, any>>(
		(result, { path, field }, columnIndex) => {
			let decoder: DriverValueDecoder<unknown, unknown>;
			if (is(field, Column)) {
				decoder = field;
			} else if (is(field, SQL)) {
				decoder = field.decoder;
			} else if (is(field, Subquery)) {
				decoder = field._.sql.decoder;
			} else {
				decoder = field.sql.decoder;
			}
			let node = result;
			for (const [pathChunkIndex, pathChunk] of path.entries()) {
				if (pathChunkIndex < path.length - 1) {
					if (!(pathChunk in node)) {
						node[pathChunk] = {};
					}
					node = node[pathChunk];
				} else {
					const rawValue = row[columnIndex]!;
					const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);

					if (joinsNotNullableMap && is(field, Column) && path.length === 2) {
						const objectName = path[0]!;
						if (!(objectName in nullifyMap)) {
							nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
						} else if (
							typeof nullifyMap[objectName] === 'string' && nullifyMap[objectName] !== getTableName(field.table)
						) {
							nullifyMap[objectName] = false;
						}
					}
				}
			}
			return result;
		},
		{},
// ... (283 more lines)

Domain

Subdomains

Frequently Asked Questions

What does utils.ts do?
utils.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, DatabaseDrivers subdomain.
What functions are defined in utils.ts?
utils.ts defines 12 function(s): Promise, T, applyMixins, getColumnNameAndConfig, getTableColumns, getTableLikeName, getViewSelectedFields, haveSameKeys, isConfig, mapResultRow, and 2 more.
What does utils.ts depend on?
utils.ts imports 19 module(s): Column, Param, SQL, Subquery, Subquery, Table, Table, cache.ts, and 11 more.
What files import utils.ts?
utils.ts is imported by 5 file(s): casing.ts, column-builder.ts, column.ts, relations.ts, table.ts.
Where is utils.ts in the architecture?
utils.ts is located at drizzle-orm/src/utils.ts (domain: DrizzleORM, subdomain: DatabaseDrivers, directory: drizzle-orm/src).

Analyze Your Own Codebase

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

Try Supermodel Free