Home / Class/ TiDBServerlessTransaction Class — drizzle-orm Architecture

TiDBServerlessTransaction Class — drizzle-orm Architecture

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

Entity Profile

Dependency Diagram

graph TD
  af5b1bd6_529c_c417_9e7e_86a57f414237["TiDBServerlessTransaction"]
  baed709d_8779_aa82_55d7_015a29a37065["session.ts"]
  af5b1bd6_529c_c417_9e7e_86a57f414237 -->|defined in| baed709d_8779_aa82_55d7_015a29a37065
  e591ae4d_fc1c_912e_f7aa_b060f49ed8c2["constructor()"]
  af5b1bd6_529c_c417_9e7e_86a57f414237 -->|method| e591ae4d_fc1c_912e_f7aa_b060f49ed8c2
  3c5541de_40e9_f9b6_c940_ea976fc1b1b9["transaction()"]
  af5b1bd6_529c_c417_9e7e_86a57f414237 -->|method| 3c5541de_40e9_f9b6_c940_ea976fc1b1b9

Relationship Graph

Source Code

drizzle-orm/src/tidb-serverless/session.ts lines 194–229

export class TiDBServerlessTransaction<
	TFullSchema extends Record<string, unknown>,
	TSchema extends TablesRelationalConfig,
> extends MySqlTransaction<TiDBServerlessQueryResultHKT, TiDBServerlessPreparedQueryHKT, TFullSchema, TSchema> {
	static override readonly [entityKind]: string = 'TiDBServerlessTransaction';

	constructor(
		dialect: MySqlDialect,
		session: MySqlSession,
		schema: RelationalSchemaConfig<TSchema> | undefined,
		nestedIndex = 0,
	) {
		super(dialect, session, schema, nestedIndex, 'default');
	}

	override async transaction<T>(
		transaction: (tx: TiDBServerlessTransaction<TFullSchema, TSchema>) => Promise<T>,
	): Promise<T> {
		const savepointName = `sp${this.nestedIndex + 1}`;
		const tx = new TiDBServerlessTransaction<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

Frequently Asked Questions

What is the TiDBServerlessTransaction class?
TiDBServerlessTransaction is a class in the drizzle-orm codebase, defined in drizzle-orm/src/tidb-serverless/session.ts.
Where is TiDBServerlessTransaction defined?
TiDBServerlessTransaction is defined in drizzle-orm/src/tidb-serverless/session.ts at line 194.

Analyze Your Own Codebase

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

Try Supermodel Free