Home / Class/ SQLiteDOPreparedQuery Class — drizzle-orm Architecture

SQLiteDOPreparedQuery Class — drizzle-orm Architecture

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

Entity Profile

Dependency Diagram

graph TD
  305e702d_be56_5898_972e_085e3f4318f8["SQLiteDOPreparedQuery"]
  c22bad06_c896_0354_24e6_1e145c15794e["session.ts"]
  305e702d_be56_5898_972e_085e3f4318f8 -->|defined in| c22bad06_c896_0354_24e6_1e145c15794e
  0ab1fae8_9af9_2ce6_e7a4_f8d73a7e299f["constructor()"]
  305e702d_be56_5898_972e_085e3f4318f8 -->|method| 0ab1fae8_9af9_2ce6_e7a4_f8d73a7e299f
  a247598d_86ed_0e48_d629_f0c16c5e72b0["run()"]
  305e702d_be56_5898_972e_085e3f4318f8 -->|method| a247598d_86ed_0e48_d629_f0c16c5e72b0
  14575581_6421_cf31_289b_7f4a7224ec9e["all()"]
  305e702d_be56_5898_972e_085e3f4318f8 -->|method| 14575581_6421_cf31_289b_7f4a7224ec9e
  7ff7e6ed_c8c0_9e84_e139_3ccca17997e2["get()"]
  305e702d_be56_5898_972e_085e3f4318f8 -->|method| 7ff7e6ed_c8c0_9e84_e139_3ccca17997e2
  315cf6f5_a530_4793_23df_a54524079fc2["values()"]
  305e702d_be56_5898_972e_085e3f4318f8 -->|method| 315cf6f5_a530_4793_23df_a54524079fc2
  4019197b_567c_c41d_93a0_e85eca06893a["isResponseInArrayMode()"]
  305e702d_be56_5898_972e_085e3f4318f8 -->|method| 4019197b_567c_c41d_93a0_e85eca06893a

Relationship Graph

Source Code

drizzle-orm/src/durable-sqlite/session.ts lines 90–177

export class SQLiteDOPreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends PreparedQueryBase<{
	type: 'sync';
	run: void;
	all: T['all'];
	get: T['get'];
	values: T['values'];
	execute: T['execute'];
}> {
	static override readonly [entityKind]: string = 'SQLiteDOPreparedQuery';

	constructor(
		private client: DurableObjectStorage,
		query: Query,
		private logger: Logger,
		private fields: SelectedFieldsOrdered | undefined,
		executeMethod: SQLiteExecuteMethod,
		private _isResponseInArrayMode: boolean,
		private customResultMapper?: (rows: unknown[][]) => unknown,
	) {
		// 3-6 params are for cache. As long as we don't support sync cache - it will be skipped here
		super('sync', executeMethod, query, undefined, undefined, undefined);
	}

	run(placeholderValues?: Record<string, unknown>): void {
		const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
		this.logger.logQuery(this.query.sql, params);

		params.length > 0 ? this.client.sql.exec(this.query.sql, ...params) : this.client.sql.exec(this.query.sql);
	}

	all(placeholderValues?: Record<string, unknown>): T['all'] {
		const { fields, joinsNotNullableMap, query, logger, client, customResultMapper } = this;
		if (!fields && !customResultMapper) {
			const params = fillPlaceholders(query.params, placeholderValues ?? {});
			logger.logQuery(query.sql, params);

			return params.length > 0 ? client.sql.exec(query.sql, ...params).toArray() : client.sql.exec(query.sql).toArray();
		}

		const rows = this.values(placeholderValues) as unknown[][];

		if (customResultMapper) {
			return customResultMapper(rows) as T['all'];
		}

		return rows.map((row) => mapResultRow(fields!, row, joinsNotNullableMap));
	}

	get(placeholderValues?: Record<string, unknown>): T['get'] {
		const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
		this.logger.logQuery(this.query.sql, params);

		const { fields, client, joinsNotNullableMap, customResultMapper, query } = this;
		if (!fields && !customResultMapper) {
			return (params.length > 0 ? client.sql.exec(query.sql, ...params) : client.sql.exec(query.sql)).next().value;
		}

		const rows = this.values(placeholderValues) as unknown[][];
		const row = rows[0];

		if (!row) {
			return undefined;
		}

		if (customResultMapper) {
			return customResultMapper(rows) as T['get'];
		}

		return mapResultRow(fields!, row, joinsNotNullableMap);
	}

	values(placeholderValues?: Record<string, unknown>): T['values'] {
		const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
		this.logger.logQuery(this.query.sql, params);

		const res = params.length > 0
			? this.client.sql.exec(this.query.sql, ...params)
			: this.client.sql.exec(this.query.sql);

		// @ts-ignore .raw().toArray() exists
		return res.raw().toArray();

Domain

Frequently Asked Questions

What is the SQLiteDOPreparedQuery class?
SQLiteDOPreparedQuery is a class in the drizzle-orm codebase, defined in drizzle-orm/src/durable-sqlite/session.ts.
Where is SQLiteDOPreparedQuery defined?
SQLiteDOPreparedQuery is defined in drizzle-orm/src/durable-sqlite/session.ts at line 90.

Analyze Your Own Codebase

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

Try Supermodel Free