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

session.ts — drizzle-orm Source File

Architecture documentation for session.ts, a typescript file in the drizzle-orm codebase. 13 imports, 3 dependents.

File typescript DrizzleORM RelationalQuery 13 imports 3 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  ed95da34_4512_ad89_e501_f8ef5d5e539d["session.ts"]
  9b087225_652d_6b65_62a9_87af0bff69c9["db.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> 9b087225_652d_6b65_62a9_87af0bff69c9
  2d57d0b7_4a77_af8e_8027_62a4fb11f803["GelDatabase"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> 2d57d0b7_4a77_af8e_8027_62a4fb11f803
  6972d39c_a1ff_d9cf_1e99_15f684fd5e42["dialect.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> 6972d39c_a1ff_d9cf_1e99_15f684fd5e42
  1802ae0d_e56f_7575_eb4a_b95e50f061c0["select.types.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> 1802ae0d_e56f_7575_eb4a_b95e50f061c0
  4509cca4_7fd9_2ecd_1b7c_1ef1c0ee30c4["cache.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> 4509cca4_7fd9_2ecd_1b7c_1ef1c0ee30c4
  47a9c453_10f1_a759_6246_695fcce2b20a["types.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> 47a9c453_10f1_a759_6246_695fcce2b20a
  27705a9d_afe9_57dd_8c97_e52d8a67d426["entity.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> 27705a9d_afe9_57dd_8c97_e52d8a67d426
  a633174a_152a_5e1c_73b0_aa56a1f1c3c5["errors.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> a633174a_152a_5e1c_73b0_aa56a1f1c3c5
  e4d6a0ab_9aa2_13a6_a2f1_58d94314c3f2["relations.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> e4d6a0ab_9aa2_13a6_a2f1_58d94314c3f2
  547e9370_8c5e_e9f1_3d6f_b9a83ab3d562["session.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> 547e9370_8c5e_e9f1_3d6f_b9a83ab3d562
  944a2bed_8787_5f43_03e5_9a3b696c293c["index.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> 944a2bed_8787_5f43_03e5_9a3b696c293c
  051cc2d2_fe6f_16df_aaec_3b341d2c2576["tracing.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> 051cc2d2_fe6f_16df_aaec_3b341d2c2576
  ecce3253_1e75_a87f_27b3_ca87e81a3024["utils.ts"]
  ed95da34_4512_ad89_e501_f8ef5d5e539d --> ecce3253_1e75_a87f_27b3_ca87e81a3024
  4d703ec7_e74f_0420_0cd8_9b3940f02f76["count.ts"]
  4d703ec7_e74f_0420_0cd8_9b3940f02f76 --> ed95da34_4512_ad89_e501_f8ef5d5e539d
  style ed95da34_4512_ad89_e501_f8ef5d5e539d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { type Cache, hashQuery, NoopCache } from '~/cache/core/cache.ts';
import type { WithCacheConfig } from '~/cache/core/types.ts';
import { entityKind, is } from '~/entity.ts';
import { DrizzleQueryError, TransactionRollbackError } from '~/errors.ts';
import type { TablesRelationalConfig } from '~/relations.ts';
import type { PreparedQuery } from '~/session.ts';
import type { Query, SQL } from '~/sql/index.ts';
import { tracer } from '~/tracing.ts';
import type { NeonAuthToken } from '~/utils.ts';
import { GelDatabase } from './db.ts';
import type { GelDialect } from './dialect.ts';
import type { SelectedFieldsOrdered } from './query-builders/select.types.ts';

export interface PreparedQueryConfig {
	execute: unknown;
	all: unknown;
	values: unknown;
}

export abstract class GelPreparedQuery<T extends PreparedQueryConfig> implements PreparedQuery {
	constructor(
		protected query: Query,
		private cache?: Cache,
		// per query related metadata
		private queryMetadata?: {
			type: 'select' | 'update' | 'delete' | 'insert';
			tables: string[];
		} | undefined,
		// config that was passed through $withCache
		private cacheConfig?: WithCacheConfig,
	) {
		// it means that no $withCache options were passed and it should be just enabled
		if (cache && cache.strategy() === 'all' && cacheConfig === undefined) {
			this.cacheConfig = { enable: true, autoInvalidate: true };
		}
		if (!this.cacheConfig?.enable) {
			this.cacheConfig = undefined;
		}
	}

	/** @internal */
	protected async queryWithCache<T>(
		queryString: string,
		params: any[],
		query: () => Promise<T>,
	): Promise<T> {
		if (this.cache === undefined || is(this.cache, NoopCache) || this.queryMetadata === undefined) {
			try {
				return await query();
			} catch (e) {
				throw new DrizzleQueryError(queryString, params, e as Error);
			}
		}

		// don't do any mutations, if globally is false
		if (this.cacheConfig && !this.cacheConfig.enable) {
			try {
				return await query();
			} catch (e) {
				throw new DrizzleQueryError(queryString, params, e as Error);
// ... (188 more lines)

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does session.ts do?
session.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, RelationalQuery subdomain.
What functions are defined in session.ts?
session.ts defines 2 function(s): rows, tx.
What does session.ts depend on?
session.ts imports 13 module(s): GelDatabase, cache.ts, db.ts, dialect.ts, entity.ts, errors.ts, index.ts, relations.ts, and 5 more.
What files import session.ts?
session.ts is imported by 3 file(s): count.ts, query.ts, select.types.ts.
Where is session.ts in the architecture?
session.ts is located at drizzle-orm/src/gel-core/session.ts (domain: DrizzleORM, subdomain: RelationalQuery, directory: drizzle-orm/src/gel-core).

Analyze Your Own Codebase

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

Try Supermodel Free