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

execute() — drizzle-orm Function Reference

Architecture documentation for the execute() function in session.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  c0985bf1_a13b_987c_f5d2_c760e55bb5ac["execute()"]
  b5211596_b01a_8163_ac2a_e294cfd2534a["PostgresJsPreparedQuery"]
  c0985bf1_a13b_987c_f5d2_c760e55bb5ac -->|defined in| b5211596_b01a_8163_ac2a_e294cfd2534a
  style c0985bf1_a13b_987c_f5d2_c760e55bb5ac fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/postgres-js/session.ts lines 38–74

	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', () => {
					return this.queryWithCache(query, params, async () => {
						return await client.unsafe(query, params as any[]);
					});
				});
			}

			const rows = await tracer.startActiveSpan('drizzle.driver.execute', () => {
				span?.setAttributes({
					'drizzle.query.text': query,
					'drizzle.query.params': JSON.stringify(params),
				});
				return this.queryWithCache(query, params, async () => {
					return await 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));
			});
		});
	}

Domain

Subdomains

Frequently Asked Questions

What does execute() do?
execute() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/postgres-js/session.ts.
Where is execute() defined?
execute() is defined in drizzle-orm/src/postgres-js/session.ts at line 38.

Analyze Your Own Codebase

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

Try Supermodel Free