PostgresJsPreparedQuery Class — drizzle-orm Architecture
Architecture documentation for the PostgresJsPreparedQuery class in session.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD b5211596_b01a_8163_ac2a_e294cfd2534a["PostgresJsPreparedQuery"] 72a101a5_a087_5795_1ea2_26f9e19eeff9["session.ts"] b5211596_b01a_8163_ac2a_e294cfd2534a -->|defined in| 72a101a5_a087_5795_1ea2_26f9e19eeff9 cd0ea87b_9826_a83c_1a41_f63aae505137["constructor()"] b5211596_b01a_8163_ac2a_e294cfd2534a -->|method| cd0ea87b_9826_a83c_1a41_f63aae505137 c0985bf1_a13b_987c_f5d2_c760e55bb5ac["execute()"] b5211596_b01a_8163_ac2a_e294cfd2534a -->|method| c0985bf1_a13b_987c_f5d2_c760e55bb5ac 429a17f2_9159_fa9c_2f02_6bbe8e07e774["all()"] b5211596_b01a_8163_ac2a_e294cfd2534a -->|method| 429a17f2_9159_fa9c_2f02_6bbe8e07e774 61490d6c_ddb0_a5f1_7cd5_3941cf6e5e08["isResponseInArrayMode()"] b5211596_b01a_8163_ac2a_e294cfd2534a -->|method| 61490d6c_ddb0_a5f1_7cd5_3941cf6e5e08
Relationship Graph
Source Code
drizzle-orm/src/postgres-js/session.ts lines 17–100
export class PostgresJsPreparedQuery<T extends PreparedQueryConfig> extends PgPreparedQuery<T> {
static override readonly [entityKind]: string = 'PostgresJsPreparedQuery';
constructor(
private client: Sql,
private queryString: string,
private params: unknown[],
private logger: Logger,
cache: Cache,
queryMetadata: {
type: 'select' | 'update' | 'delete' | 'insert';
tables: string[];
} | undefined,
cacheConfig: WithCacheConfig | undefined,
private fields: SelectedFieldsOrdered | undefined,
private _isResponseInArrayMode: boolean,
private customResultMapper?: (rows: unknown[][]) => T['execute'],
) {
super({ sql: queryString, params }, cache, queryMetadata, cacheConfig);
}
async execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {
return tracer.startActiveSpan('drizzle.execute', async (span) => {
const params = fillPlaceholders(this.params, placeholderValues);
span?.setAttributes({
'drizzle.query.text': this.queryString,
'drizzle.query.params': JSON.stringify(params),
});
this.logger.logQuery(this.queryString, params);
const { fields, queryString: query, client, joinsNotNullableMap, customResultMapper } = this;
if (!fields && !customResultMapper) {
return tracer.startActiveSpan('drizzle.driver.execute', () => {
return this.queryWithCache(query, params, async () => {
return await client.unsafe(query, params as any[]);
});
});
}
const rows = await tracer.startActiveSpan('drizzle.driver.execute', () => {
span?.setAttributes({
'drizzle.query.text': query,
'drizzle.query.params': JSON.stringify(params),
});
return this.queryWithCache(query, params, async () => {
return await client.unsafe(query, params as any[]).values();
});
});
return tracer.startActiveSpan('drizzle.mapResponse', () => {
return customResultMapper
? customResultMapper(rows)
: rows.map((row) => mapResultRow<T['execute']>(fields!, row, joinsNotNullableMap));
});
});
}
all(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['all']> {
return tracer.startActiveSpan('drizzle.execute', async (span) => {
const params = fillPlaceholders(this.params, placeholderValues);
span?.setAttributes({
'drizzle.query.text': this.queryString,
'drizzle.query.params': JSON.stringify(params),
});
this.logger.logQuery(this.queryString, params);
return tracer.startActiveSpan('drizzle.driver.execute', () => {
span?.setAttributes({
'drizzle.query.text': this.queryString,
'drizzle.query.params': JSON.stringify(params),
});
return this.queryWithCache(this.queryString, params, async () => {
return this.client.unsafe(this.queryString, params as any[]);
});
});
});
}
/** @internal */
isResponseInArrayMode(): boolean {
Domain
Defined In
Source
Frequently Asked Questions
What is the PostgresJsPreparedQuery class?
PostgresJsPreparedQuery is a class in the drizzle-orm codebase, defined in drizzle-orm/src/postgres-js/session.ts.
Where is PostgresJsPreparedQuery defined?
PostgresJsPreparedQuery is defined in drizzle-orm/src/postgres-js/session.ts at line 17.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free