Home / Class/ BunSQLPreparedQuery Class — drizzle-orm Architecture

BunSQLPreparedQuery Class — drizzle-orm Architecture

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

Entity Profile

Dependency Diagram

graph TD
  2c4d0f43_8e7b_aeb6_a9d5_fb15fdd1555b["BunSQLPreparedQuery"]
  18315257_3b48_a60d_f8cf_ea5ba47f9fd5["session.ts"]
  2c4d0f43_8e7b_aeb6_a9d5_fb15fdd1555b -->|defined in| 18315257_3b48_a60d_f8cf_ea5ba47f9fd5
  362c4db7_ece9_10f2_7b85_787c6b1c218f["constructor()"]
  2c4d0f43_8e7b_aeb6_a9d5_fb15fdd1555b -->|method| 362c4db7_ece9_10f2_7b85_787c6b1c218f
  a167f59e_2b48_9d10_c5fc_7cb7463f69c4["execute()"]
  2c4d0f43_8e7b_aeb6_a9d5_fb15fdd1555b -->|method| a167f59e_2b48_9d10_c5fc_7cb7463f69c4
  1786b434_9304_ff29_cf11_2153c974d8ec["all()"]
  2c4d0f43_8e7b_aeb6_a9d5_fb15fdd1555b -->|method| 1786b434_9304_ff29_cf11_2153c974d8ec
  308b64e3_8a23_9f92_53fc_3b9a76a2aff4["isResponseInArrayMode()"]
  2c4d0f43_8e7b_aeb6_a9d5_fb15fdd1555b -->|method| 308b64e3_8a23_9f92_53fc_3b9a76a2aff4

Relationship Graph

Source Code

drizzle-orm/src/bun-sql/session.ts lines 19–103

export class BunSQLPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {
	static override readonly [entityKind]: string = 'BunSQLPreparedQuery';

	constructor(
		private client: SQL,
		private queryString: string,
		private params: unknown[],
		private logger: Logger,
		cache: Cache,
		queryMetadata: {
			type: 'select' | 'update' | 'delete' | 'insert';
			tables: string[];
		} | undefined,
		cacheConfig: WithCacheConfig | undefined,
		private fields: SelectedFieldsOrdered | undefined,
		private _isResponseInArrayMode: boolean,
		private customResultMapper?: (rows: unknown[][]) => T['execute'],
	) {
		super({ sql: queryString, params }, cache, queryMetadata, cacheConfig);
	}

	async execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {
		return tracer.startActiveSpan('drizzle.execute', async (span) => {
			const params = fillPlaceholders(this.params, placeholderValues);

			span?.setAttributes({
				'drizzle.query.text': this.queryString,
				'drizzle.query.params': JSON.stringify(params),
			});

			this.logger.logQuery(this.queryString, params);

			const { fields, queryString: query, client, joinsNotNullableMap, customResultMapper } = this;
			if (!fields && !customResultMapper) {
				return tracer.startActiveSpan('drizzle.driver.execute', async () => {
					return await this.queryWithCache(query, params, async () => {
						return await client.unsafe(query, params as any[]);
					});
				});
			}

			const rows: any[] = await tracer.startActiveSpan('drizzle.driver.execute', async () => {
				span?.setAttributes({
					'drizzle.query.text': query,
					'drizzle.query.params': JSON.stringify(params),
				});

				return await this.queryWithCache(query, params, async () => {
					return client.unsafe(query, params as any[]).values();
				});
			});

			return tracer.startActiveSpan('drizzle.mapResponse', () => {
				return customResultMapper
					? customResultMapper(rows)
					: rows.map((row) => mapResultRow<T['execute']>(fields!, row, joinsNotNullableMap));
			});
		});
	}

	all(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {
		return tracer.startActiveSpan('drizzle.execute', async (span) => {
			const params = fillPlaceholders(this.params, placeholderValues);
			span?.setAttributes({
				'drizzle.query.text': this.queryString,
				'drizzle.query.params': JSON.stringify(params),
			});
			this.logger.logQuery(this.queryString, params);
			return tracer.startActiveSpan('drizzle.driver.execute', async () => {
				span?.setAttributes({
					'drizzle.query.text': this.queryString,
					'drizzle.query.params': JSON.stringify(params),
				});
				return await this.queryWithCache(this.queryString, params, async () => {
					return await this.client.unsafe(this.queryString, params as any[]);
				});
			});
		});
	}

	/** @internal */

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free