Home / Class/ VercelPgSession Class — drizzle-orm Architecture

VercelPgSession Class — drizzle-orm Architecture

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

Entity Profile

Dependency Diagram

graph TD
  81a4e159_1fd1_64d3_dcd4_a1fbabbc531f["VercelPgSession"]
  5332ec54_ebfc_a1f4_a95c_2a39ae467e61["session.ts"]
  81a4e159_1fd1_64d3_dcd4_a1fbabbc531f -->|defined in| 5332ec54_ebfc_a1f4_a95c_2a39ae467e61
  04ed5455_b56a_2a80_2dfc_cead2451a9a4["constructor()"]
  81a4e159_1fd1_64d3_dcd4_a1fbabbc531f -->|method| 04ed5455_b56a_2a80_2dfc_cead2451a9a4
  c2e6f1f7_68f0_00b9_5bee_f9d97caccd76["prepareQuery()"]
  81a4e159_1fd1_64d3_dcd4_a1fbabbc531f -->|method| c2e6f1f7_68f0_00b9_5bee_f9d97caccd76
  9fa92c53_c3c3_cffb_2558_ce861e065247["query()"]
  81a4e159_1fd1_64d3_dcd4_a1fbabbc531f -->|method| 9fa92c53_c3c3_cffb_2558_ce861e065247
  3b02a006_1c28_4844_6fff_156d61295319["queryObjects()"]
  81a4e159_1fd1_64d3_dcd4_a1fbabbc531f -->|method| 3b02a006_1c28_4844_6fff_156d61295319
  5299b678_cc08_062c_b51f_23ce15be120a["count()"]
  81a4e159_1fd1_64d3_dcd4_a1fbabbc531f -->|method| 5299b678_cc08_062c_b51f_23ce15be120a
  c336da65_f93c_cb64_7b24_385b17f7a894["transaction()"]
  81a4e159_1fd1_64d3_dcd4_a1fbabbc531f -->|method| c336da65_f93c_cb64_7b24_385b17f7a894

Relationship Graph

Source Code

drizzle-orm/src/vercel-postgres/session.ts lines 188–280

export class VercelPgSession<
	TFullSchema extends Record<string, unknown>,
	TSchema extends TablesRelationalConfig,
> extends PgSession<VercelPgQueryResultHKT, TFullSchema, TSchema> {
	static override readonly [entityKind]: string = 'VercelPgSession';

	private logger: Logger;
	private cache: Cache;

	constructor(
		private client: VercelPgClient,
		dialect: PgDialect,
		private schema: RelationalSchemaConfig<TSchema> | undefined,
		private options: VercelPgSessionOptions = {},
	) {
		super(dialect);
		this.logger = options.logger ?? new NoopLogger();
		this.cache = options.cache ?? new NoopCache();
	}

	prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(
		query: Query,
		fields: SelectedFieldsOrdered | undefined,
		name: string | undefined,
		isResponseInArrayMode: boolean,
		customResultMapper?: (rows: unknown[][]) => T['execute'],
		queryMetadata?: {
			type: 'select' | 'update' | 'delete' | 'insert';
			tables: string[];
		},
		cacheConfig?: WithCacheConfig,
	): PgPreparedQuery<T> {
		return new VercelPgPreparedQuery(
			this.client,
			query.sql,
			query.params,
			this.logger,
			this.cache,
			queryMetadata,
			cacheConfig,
			fields,
			name,
			isResponseInArrayMode,
			customResultMapper,
		);
	}

	async query(query: string, params: unknown[]): Promise<QueryResult> {
		this.logger.logQuery(query, params);
		const result = await this.client.query({
			rowMode: 'array',
			text: query,
			values: params,
		});
		return result;
	}

	async queryObjects<T extends QueryResultRow>(
		query: string,
		params: unknown[],
	): Promise<QueryResult<T>> {
		return this.client.query<T>(query, params);
	}

	override async count(sql: SQL): Promise<number> {
		const result = await this.execute(sql);

		return Number((result as any)['rows'][0]['count']);
	}

	override async transaction<T>(
		transaction: (tx: VercelPgTransaction<TFullSchema, TSchema>) => Promise<T>,
		config?: PgTransactionConfig | undefined,
	): Promise<T> {
		const session = this.client instanceof VercelPool // eslint-disable-line no-instanceof/no-instanceof
			? new VercelPgSession(await this.client.connect(), this.dialect, this.schema, this.options)
			: this;
		const tx = new VercelPgTransaction<TFullSchema, TSchema>(this.dialect, session, this.schema);
		await tx.execute(sql`begin${config ? sql` ${tx.getTransactionConfigSQL(config)}` : undefined}`);
		try {
			const result = await transaction(tx);

Domain

Frequently Asked Questions

What is the VercelPgSession class?
VercelPgSession is a class in the drizzle-orm codebase, defined in drizzle-orm/src/vercel-postgres/session.ts.
Where is VercelPgSession defined?
VercelPgSession is defined in drizzle-orm/src/vercel-postgres/session.ts at line 188.

Analyze Your Own Codebase

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

Try Supermodel Free