Home / Class/ BunSQLSession Class — drizzle-orm Architecture

BunSQLSession Class — drizzle-orm Architecture

Architecture documentation for the BunSQLSession class in session.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  d0db91ac_0ed0_7bef_698b_d0245604c64c["BunSQLSession"]
  72abdde0_f2f6_9fce_8f6c_bed0ce1fd360["session.ts"]
  d0db91ac_0ed0_7bef_698b_d0245604c64c -->|defined in| 72abdde0_f2f6_9fce_8f6c_bed0ce1fd360
  aef94462_025a_d4c5_877c_421dafe3b3ef["constructor()"]
  d0db91ac_0ed0_7bef_698b_d0245604c64c -->|method| aef94462_025a_d4c5_877c_421dafe3b3ef
  752f5d1c_0d04_6a6c_b3b0_1c045ded7d71["prepareQuery()"]
  d0db91ac_0ed0_7bef_698b_d0245604c64c -->|method| 752f5d1c_0d04_6a6c_b3b0_1c045ded7d71
  97007a54_4ff8_f3af_0c4c_7409a36589ad["query()"]
  d0db91ac_0ed0_7bef_698b_d0245604c64c -->|method| 97007a54_4ff8_f3af_0c4c_7409a36589ad
  1f658ad1_a0bc_88af_e6ef_4b58abd15318["queryObjects()"]
  d0db91ac_0ed0_7bef_698b_d0245604c64c -->|method| 1f658ad1_a0bc_88af_e6ef_4b58abd15318
  929da0b5_8428_a379_60b9_c7bca1c33565["transaction()"]
  d0db91ac_0ed0_7bef_698b_d0245604c64c -->|method| 929da0b5_8428_a379_60b9_c7bca1c33565

Relationship Graph

Source Code

drizzle-orm/src/bun-sql/session.ts lines 110–188

export class BunSQLSession<
	TSQL extends SQL,
	TFullSchema extends Record<string, unknown>,
	TSchema extends TablesRelationalConfig,
> extends PgSession<BunSQLQueryResultHKT, TFullSchema, TSchema> {
	static override readonly [entityKind]: string = 'BunSQLSession';

	logger: Logger;
	private cache: Cache;

	constructor(
		public client: TSQL,
		dialect: PgDialect,
		private schema: RelationalSchemaConfig<TSchema> | undefined,
		/** @internal */
		readonly options: BunSQLSessionOptions = {},
	) {
		super(dialect);
		this.logger = options.logger ?? new NoopLogger();
		this.cache = options.cache ?? new NoopCache();
	}

	prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(
		query: Query,
		fields: SelectedFieldsOrdered | undefined,
		name: string | undefined,
		isResponseInArrayMode: boolean,
		customResultMapper?: (rows: unknown[][]) => T['execute'],
		queryMetadata?: {
			type: 'select' | 'update' | 'delete' | 'insert';
			tables: string[];
		},
		cacheConfig?: WithCacheConfig,
	): PgPreparedQuery<T> {
		return new BunSQLPreparedQuery(
			this.client,
			query.sql,
			query.params,
			this.logger,
			this.cache,
			queryMetadata,
			cacheConfig,
			fields,
			isResponseInArrayMode,
			customResultMapper,
		);
	}

	query(query: string, params: unknown[]): Promise<any> {
		this.logger.logQuery(query, params);
		return this.client.unsafe(query, params as any[]).values();
	}

	queryObjects(
		query: string,
		params: unknown[],
	): Promise<any> {
		return this.client.unsafe(query, params as any[]);
	}

	override transaction<T>(
		transaction: (tx: BunSQLTransaction<TFullSchema, TSchema>) => Promise<T>,
		config?: PgTransactionConfig,
	): Promise<T> {
		return this.client.begin(async (client) => {
			const session = new BunSQLSession<TransactionSQL, TFullSchema, TSchema>(
				client,
				this.dialect,
				this.schema,
				this.options,
			);
			const tx = new BunSQLTransaction(this.dialect, session, this.schema);
			if (config) {
				await tx.setTransaction(config);
			}
			return transaction(tx);
		}) as Promise<T>;
	}
}

Domain

Frequently Asked Questions

What is the BunSQLSession class?
BunSQLSession is a class in the drizzle-orm codebase, defined in drizzle-orm/src/bun-sql/session.ts.
Where is BunSQLSession defined?
BunSQLSession is defined in drizzle-orm/src/bun-sql/session.ts at line 110.

Analyze Your Own Codebase

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

Try Supermodel Free