LibSQLPreparedQuery Class — drizzle-orm Architecture
Architecture documentation for the LibSQLPreparedQuery class in session.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD c2d257fe_c7e1_f3d2_0b3e_6513a71b51aa["LibSQLPreparedQuery"] 71955c9c_98bb_2bea_3a87_96f5a4be3a27["session.ts"] c2d257fe_c7e1_f3d2_0b3e_6513a71b51aa -->|defined in| 71955c9c_98bb_2bea_3a87_96f5a4be3a27 c73bd0ae_cb97_f3c4_2617_eb9cf1c5cd4f["constructor()"] c2d257fe_c7e1_f3d2_0b3e_6513a71b51aa -->|method| c73bd0ae_cb97_f3c4_2617_eb9cf1c5cd4f 5fca71bb_d9cb_5189_8a34_fca357bfc756["run()"] c2d257fe_c7e1_f3d2_0b3e_6513a71b51aa -->|method| 5fca71bb_d9cb_5189_8a34_fca357bfc756 5808e672_0c41_183e_adf5_5e2d932c3688["all()"] c2d257fe_c7e1_f3d2_0b3e_6513a71b51aa -->|method| 5808e672_0c41_183e_adf5_5e2d932c3688 0ebedd2f_560f_70d5_c8db_aad7d2095ec8["mapAllResult()"] c2d257fe_c7e1_f3d2_0b3e_6513a71b51aa -->|method| 0ebedd2f_560f_70d5_c8db_aad7d2095ec8 9c25c357_e2a3_c9a0_3df1_faff95cb1470["get()"] c2d257fe_c7e1_f3d2_0b3e_6513a71b51aa -->|method| 9c25c357_e2a3_c9a0_3df1_faff95cb1470 a09e10ee_6a96_c8f9_dfb6_0a4f5bd6a0ee["mapGetResult()"] c2d257fe_c7e1_f3d2_0b3e_6513a71b51aa -->|method| a09e10ee_6a96_c8f9_dfb6_0a4f5bd6a0ee b154273b_d1f8_b7eb_87d0_fd7e60d8b434["values()"] c2d257fe_c7e1_f3d2_0b3e_6513a71b51aa -->|method| b154273b_d1f8_b7eb_87d0_fd7e60d8b434 4af57c0f_1c26_1cb1_cc10_717a9c8af48e["isResponseInArrayMode()"] c2d257fe_c7e1_f3d2_0b3e_6513a71b51aa -->|method| 4af57c0f_1c26_1cb1_cc10_717a9c8af48e
Relationship Graph
Source Code
drizzle-orm/src/libsql/session.ts lines 165–298
export class LibSQLPreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends SQLitePreparedQuery<
{ type: 'async'; run: ResultSet; all: T['all']; get: T['get']; values: T['values']; execute: T['execute'] }
> {
static override readonly [entityKind]: string = 'LibSQLPreparedQuery';
constructor(
private client: Client,
query: Query,
private logger: Logger,
cache: Cache,
queryMetadata: {
type: 'select' | 'update' | 'delete' | 'insert';
tables: string[];
} | undefined,
cacheConfig: WithCacheConfig | undefined,
/** @internal */ public fields: SelectedFieldsOrdered | undefined,
private tx: Transaction | undefined,
executeMethod: SQLiteExecuteMethod,
private _isResponseInArrayMode: boolean,
/** @internal */ public customResultMapper?: (
rows: unknown[][],
mapColumnValue?: (value: unknown) => unknown,
) => unknown,
) {
super('async', executeMethod, query, cache, queryMetadata, cacheConfig);
this.customResultMapper = customResultMapper;
this.fields = fields;
}
async run(placeholderValues?: Record<string, unknown>): Promise<ResultSet> {
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
this.logger.logQuery(this.query.sql, params);
return await this.queryWithCache(this.query.sql, params, async () => {
const stmt: InStatement = { sql: this.query.sql, args: params as InArgs };
return this.tx ? this.tx.execute(stmt) : this.client.execute(stmt);
});
}
async all(placeholderValues?: Record<string, unknown>): Promise<T['all']> {
const { fields, logger, query, tx, client, customResultMapper } = this;
if (!fields && !customResultMapper) {
const params = fillPlaceholders(query.params, placeholderValues ?? {});
logger.logQuery(query.sql, params);
return await this.queryWithCache(query.sql, params, async () => {
const stmt: InStatement = { sql: query.sql, args: params as InArgs };
return (tx ? tx.execute(stmt) : client.execute(stmt)).then(({ rows }) => this.mapAllResult(rows));
});
}
const rows = await this.values(placeholderValues) as unknown[][];
return this.mapAllResult(rows);
}
override mapAllResult(rows: unknown, isFromBatch?: boolean): unknown {
if (isFromBatch) {
rows = (rows as ResultSet).rows;
}
if (!this.fields && !this.customResultMapper) {
return (rows as unknown[]).map((row) => normalizeRow(row));
}
if (this.customResultMapper) {
return this.customResultMapper(rows as unknown[][], normalizeFieldValue) as T['all'];
}
return (rows as unknown[]).map((row) => {
return mapResultRow(
this.fields!,
Array.prototype.slice.call(row).map((v) => normalizeFieldValue(v)),
this.joinsNotNullableMap,
);
});
}
async get(placeholderValues?: Record<string, unknown>): Promise<T['get']> {
const { fields, logger, query, tx, client, customResultMapper } = this;
if (!fields && !customResultMapper) {
const params = fillPlaceholders(query.params, placeholderValues ?? {});
logger.logQuery(query.sql, params);
Domain
Defined In
Source
Frequently Asked Questions
What is the LibSQLPreparedQuery class?
LibSQLPreparedQuery is a class in the drizzle-orm codebase, defined in drizzle-orm/src/libsql/session.ts.
Where is LibSQLPreparedQuery defined?
LibSQLPreparedQuery is defined in drizzle-orm/src/libsql/session.ts at line 165.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free