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
  e97f13b3_0abe_008f_2902_c0f8644c9e20["transaction()"]
  5c838b89_938f_05a3_718d_06ed6215bf56["NodePgTransaction"]
  e97f13b3_0abe_008f_2902_c0f8644c9e20 -->|defined in| 5c838b89_938f_05a3_718d_06ed6215bf56
  2aecbcfe_6a09_c4c7_c8af_f142cff742c0["transaction()"]
  2aecbcfe_6a09_c4c7_c8af_f142cff742c0 -->|calls| e97f13b3_0abe_008f_2902_c0f8644c9e20
  f7db4a0e_fe1a_0681_7125_5036f9a2f266["execute()"]
  e97f13b3_0abe_008f_2902_c0f8644c9e20 -->|calls| f7db4a0e_fe1a_0681_7125_5036f9a2f266
  2aecbcfe_6a09_c4c7_c8af_f142cff742c0["transaction()"]
  e97f13b3_0abe_008f_2902_c0f8644c9e20 -->|calls| 2aecbcfe_6a09_c4c7_c8af_f142cff742c0
  style e97f13b3_0abe_008f_2902_c0f8644c9e20 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/node-postgres/session.ts lines 284–301

	override async transaction<T>(transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {
		const savepointName = `sp${this.nestedIndex + 1}`;
		const tx = new NodePgTransaction<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/node-postgres/session.ts.
Where is transaction() defined?
transaction() is defined in drizzle-orm/src/node-postgres/session.ts at line 284.
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