TiDBServerlessSession Class — drizzle-orm Architecture
Architecture documentation for the TiDBServerlessSession class in session.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 116b9e1a_aec8_0e35_a7cb_40d3a24bc48c["TiDBServerlessSession"] baed709d_8779_aa82_55d7_015a29a37065["session.ts"] 116b9e1a_aec8_0e35_a7cb_40d3a24bc48c -->|defined in| baed709d_8779_aa82_55d7_015a29a37065 6bbdb213_e75f_13c8_d096_366f7a96982a["constructor()"] 116b9e1a_aec8_0e35_a7cb_40d3a24bc48c -->|method| 6bbdb213_e75f_13c8_d096_366f7a96982a 7a3a0090_dbc4_6838_cff3_00b0e38233aa["prepareQuery()"] 116b9e1a_aec8_0e35_a7cb_40d3a24bc48c -->|method| 7a3a0090_dbc4_6838_cff3_00b0e38233aa 48f691ad_fa81_e448_0c04_e58df255ff70["all()"] 116b9e1a_aec8_0e35_a7cb_40d3a24bc48c -->|method| 48f691ad_fa81_e448_0c04_e58df255ff70 cdd8b201_a77f_d5f7_fe08_56014e964079["count()"] 116b9e1a_aec8_0e35_a7cb_40d3a24bc48c -->|method| cdd8b201_a77f_d5f7_fe08_56014e964079 bf8d9f11_3753_f5a9_f054_5b67be4b6f0e["transaction()"] 116b9e1a_aec8_0e35_a7cb_40d3a24bc48c -->|method| bf8d9f11_3753_f5a9_f054_5b67be4b6f0e
Relationship Graph
Source Code
drizzle-orm/src/tidb-serverless/session.ts lines 109–192
export class TiDBServerlessSession<
TFullSchema extends Record<string, unknown>,
TSchema extends TablesRelationalConfig,
> extends MySqlSession<TiDBServerlessQueryResultHKT, TiDBServerlessPreparedQueryHKT, TFullSchema, TSchema> {
static override readonly [entityKind]: string = 'TiDBServerlessSession';
private logger: Logger;
private client: Tx | Connection;
private cache: Cache;
constructor(
private baseClient: Connection,
dialect: MySqlDialect,
tx: Tx | undefined,
private schema: RelationalSchemaConfig<TSchema> | undefined,
private options: TiDBServerlessSessionOptions = {},
) {
super(dialect);
this.client = tx ?? baseClient;
this.logger = options.logger ?? new NoopLogger();
this.cache = options.cache ?? new NoopCache();
}
prepareQuery<T extends MySqlPreparedQueryConfig = MySqlPreparedQueryConfig>(
query: Query,
fields: SelectedFieldsOrdered | undefined,
customResultMapper?: (rows: unknown[][]) => T['execute'],
generatedIds?: Record<string, unknown>[],
returningIds?: SelectedFieldsOrdered,
queryMetadata?: {
type: 'select' | 'update' | 'delete' | 'insert';
tables: string[];
},
cacheConfig?: WithCacheConfig,
): MySqlPreparedQuery<T> {
return new TiDBServerlessPreparedQuery(
this.client,
query.sql,
query.params,
this.logger,
this.cache,
queryMetadata,
cacheConfig,
fields,
customResultMapper,
generatedIds,
returningIds,
);
}
override all<T = unknown>(query: SQL): Promise<T[]> {
const querySql = this.dialect.sqlToQuery(query);
this.logger.logQuery(querySql.sql, querySql.params);
return this.client.execute(querySql.sql, querySql.params) as Promise<T[]>;
}
override async count(sql: SQL): Promise<number> {
const res = await this.execute<{ rows: [{ count: string }] }>(sql);
return Number(
res['rows'][0]['count'],
);
}
override async transaction<T>(
transaction: (tx: TiDBServerlessTransaction<TFullSchema, TSchema>) => Promise<T>,
): Promise<T> {
const nativeTx = await this.baseClient.begin();
try {
const session = new TiDBServerlessSession(this.baseClient, this.dialect, nativeTx, this.schema, this.options);
const tx = new TiDBServerlessTransaction<TFullSchema, TSchema>(
this.dialect,
session as MySqlSession<any, any, any, any>,
this.schema,
);
const result = await transaction(tx);
await nativeTx.commit();
return result;
} catch (err) {
await nativeTx.rollback();
throw err;
Domain
Defined In
Source
Frequently Asked Questions
What is the TiDBServerlessSession class?
TiDBServerlessSession is a class in the drizzle-orm codebase, defined in drizzle-orm/src/tidb-serverless/session.ts.
Where is TiDBServerlessSession defined?
TiDBServerlessSession is defined in drizzle-orm/src/tidb-serverless/session.ts at line 109.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free