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

transaction() — drizzle-orm Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  d0b3aff2_b6a7_17f5_d12c_5e00e54eb727["transaction()"]
  dfe919e5_72c1_5f73_7dd8_e032793d2995["VercelPgTransaction"]
  d0b3aff2_b6a7_17f5_d12c_5e00e54eb727 -->|defined in| dfe919e5_72c1_5f73_7dd8_e032793d2995
  c336da65_f93c_cb64_7b24_385b17f7a894["transaction()"]
  c336da65_f93c_cb64_7b24_385b17f7a894 -->|calls| d0b3aff2_b6a7_17f5_d12c_5e00e54eb727
  3a6e8138_0409_5715_8044_528b249e7919["execute()"]
  d0b3aff2_b6a7_17f5_d12c_5e00e54eb727 -->|calls| 3a6e8138_0409_5715_8044_528b249e7919
  c336da65_f93c_cb64_7b24_385b17f7a894["transaction()"]
  d0b3aff2_b6a7_17f5_d12c_5e00e54eb727 -->|calls| c336da65_f93c_cb64_7b24_385b17f7a894
  style d0b3aff2_b6a7_17f5_d12c_5e00e54eb727 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/vercel-postgres/session.ts lines 288–307

	override async transaction<T>(
		transaction: (tx: VercelPgTransaction<TFullSchema, TSchema>) => Promise<T>,
	): Promise<T> {
		const savepointName = `sp${this.nestedIndex + 1}`;
		const tx = new VercelPgTransaction<TFullSchema, TSchema>(
			this.dialect,
			this.session,
			this.schema,
			this.nestedIndex + 1,
		);
		await tx.execute(sql.raw(`savepoint ${savepointName}`));
		try {
			const result = await transaction(tx);
			await tx.execute(sql.raw(`release savepoint ${savepointName}`));
			return result;
		} catch (err) {
			await tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));
			throw err;
		}
	}

Domain

Subdomains

Called By

Frequently Asked Questions

What does transaction() do?
transaction() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/vercel-postgres/session.ts.
Where is transaction() defined?
transaction() is defined in drizzle-orm/src/vercel-postgres/session.ts at line 288.
What does transaction() call?
transaction() calls 2 function(s): execute, transaction.
What calls transaction()?
transaction() is called by 1 function(s): transaction.

Analyze Your Own Codebase

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

Try Supermodel Free