PostgresJsSession Class — drizzle-orm Architecture
Architecture documentation for the PostgresJsSession class in session.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 1053eb6c_20a0_7889_a53b_cfa06854e18b["PostgresJsSession"] 72a101a5_a087_5795_1ea2_26f9e19eeff9["session.ts"] 1053eb6c_20a0_7889_a53b_cfa06854e18b -->|defined in| 72a101a5_a087_5795_1ea2_26f9e19eeff9 ed6c2e8e_9e75_ec84_4bc9_d121c5ccb828["constructor()"] 1053eb6c_20a0_7889_a53b_cfa06854e18b -->|method| ed6c2e8e_9e75_ec84_4bc9_d121c5ccb828 95715e44_4d9f_04ac_6095_ecefbe2ff02b["prepareQuery()"] 1053eb6c_20a0_7889_a53b_cfa06854e18b -->|method| 95715e44_4d9f_04ac_6095_ecefbe2ff02b e66d82ce_5990_02d5_3368_335ed74ba6e5["query()"] 1053eb6c_20a0_7889_a53b_cfa06854e18b -->|method| e66d82ce_5990_02d5_3368_335ed74ba6e5 3e60491a_d22f_6fa3_3fb5_061787d10906["queryObjects()"] 1053eb6c_20a0_7889_a53b_cfa06854e18b -->|method| 3e60491a_d22f_6fa3_3fb5_061787d10906 b0468bd2_9214_c521_acfe_8881e2e1c3be["transaction()"] 1053eb6c_20a0_7889_a53b_cfa06854e18b -->|method| b0468bd2_9214_c521_acfe_8881e2e1c3be
Relationship Graph
Source Code
drizzle-orm/src/postgres-js/session.ts lines 107–185
export class PostgresJsSession<
TSQL extends Sql,
TFullSchema extends Record<string, unknown>,
TSchema extends TablesRelationalConfig,
> extends PgSession<PostgresJsQueryResultHKT, TFullSchema, TSchema> {
static override readonly [entityKind]: string = 'PostgresJsSession';
logger: Logger;
private cache: Cache;
constructor(
public client: TSQL,
dialect: PgDialect,
private schema: RelationalSchemaConfig<TSchema> | undefined,
/** @internal */
readonly options: PostgresJsSessionOptions = {},
) {
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 PostgresJsPreparedQuery(
this.client,
query.sql,
query.params,
this.logger,
this.cache,
queryMetadata,
cacheConfig,
fields,
isResponseInArrayMode,
customResultMapper,
);
}
query(query: string, params: unknown[]): Promise<RowList<Row[]>> {
this.logger.logQuery(query, params);
return this.client.unsafe(query, params as any[]).values();
}
queryObjects<T extends Row>(
query: string,
params: unknown[],
): Promise<RowList<T[]>> {
return this.client.unsafe(query, params as any[]);
}
override transaction<T>(
transaction: (tx: PostgresJsTransaction<TFullSchema, TSchema>) => Promise<T>,
config?: PgTransactionConfig,
): Promise<T> {
return this.client.begin(async (client) => {
const session = new PostgresJsSession<TransactionSql, TFullSchema, TSchema>(
client,
this.dialect,
this.schema,
this.options,
);
const tx = new PostgresJsTransaction(this.dialect, session, this.schema);
if (config) {
await tx.setTransaction(config);
}
return transaction(tx);
}) as Promise<T>;
}
}
Domain
Defined In
Source
Frequently Asked Questions
What is the PostgresJsSession class?
PostgresJsSession is a class in the drizzle-orm codebase, defined in drizzle-orm/src/postgres-js/session.ts.
Where is PostgresJsSession defined?
PostgresJsSession is defined in drizzle-orm/src/postgres-js/session.ts at line 107.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free