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 2aecbcfe_6a09_c4c7_c8af_f142cff742c0["transaction()"] c379869d_eae7_28c1_b5ff_21c36a0fef11["NodePgSession"] 2aecbcfe_6a09_c4c7_c8af_f142cff742c0 -->|defined in| c379869d_eae7_28c1_b5ff_21c36a0fef11 e97f13b3_0abe_008f_2902_c0f8644c9e20["transaction()"] e97f13b3_0abe_008f_2902_c0f8644c9e20 -->|calls| 2aecbcfe_6a09_c4c7_c8af_f142cff742c0 f7db4a0e_fe1a_0681_7125_5036f9a2f266["execute()"] 2aecbcfe_6a09_c4c7_c8af_f142cff742c0 -->|calls| f7db4a0e_fe1a_0681_7125_5036f9a2f266 e97f13b3_0abe_008f_2902_c0f8644c9e20["transaction()"] 2aecbcfe_6a09_c4c7_c8af_f142cff742c0 -->|calls| e97f13b3_0abe_008f_2902_c0f8644c9e20 style 2aecbcfe_6a09_c4c7_c8af_f142cff742c0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-orm/src/node-postgres/session.ts lines 248–268
override async transaction<T>(
transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>,
config?: PgTransactionConfig | undefined,
): Promise<T> {
const isPool = this.client instanceof Pool || Object.getPrototypeOf(this.client).constructor.name.includes('Pool'); // eslint-disable-line no-instanceof/no-instanceof
const session = isPool
? new NodePgSession(await (<pg.Pool> this.client).connect(), this.dialect, this.schema, this.options)
: this;
const tx = new NodePgTransaction<TFullSchema, TSchema>(this.dialect, session, this.schema);
await tx.execute(sql`begin${config ? sql` ${tx.getTransactionConfigSQL(config)}` : undefined}`);
try {
const result = await transaction(tx);
await tx.execute(sql`commit`);
return result;
} catch (error) {
await tx.execute(sql`rollback`);
throw error;
} finally {
if (isPool) (session.client as PoolClient).release();
}
}
Domain
Subdomains
Defined In
Calls
Called By
Source
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 248.
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