Home / Class/ ServerSimulator Class — drizzle-orm Architecture

ServerSimulator Class — drizzle-orm Architecture

Architecture documentation for the ServerSimulator class in sqlite-proxy-batch.test.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  e3dfa896_5b55_f323_34cd_1359d1f9fc08["ServerSimulator"]
  9091bb68_e7c0_bb6e_97e5_a9d57b06e993["sqlite-proxy-batch.test.ts"]
  e3dfa896_5b55_f323_34cd_1359d1f9fc08 -->|defined in| 9091bb68_e7c0_bb6e_97e5_a9d57b06e993
  50292d24_2e7e_3eca_8bfb_20c114a3e12b["constructor()"]
  e3dfa896_5b55_f323_34cd_1359d1f9fc08 -->|method| 50292d24_2e7e_3eca_8bfb_20c114a3e12b
  ad38d5d8_109f_ea54_c8fc_d11f94d79ae4["batch()"]
  e3dfa896_5b55_f323_34cd_1359d1f9fc08 -->|method| ad38d5d8_109f_ea54_c8fc_d11f94d79ae4
  0cdd2724_3fd4_132d_714b_7cb3de9b5d83["query()"]
  e3dfa896_5b55_f323_34cd_1359d1f9fc08 -->|method| 0cdd2724_3fd4_132d_714b_7cb3de9b5d83
  bcb2beed_e076_95ee_6aec_b6af459d9280["migrations()"]
  e3dfa896_5b55_f323_34cd_1359d1f9fc08 -->|method| bcb2beed_e076_95ee_6aec_b6af459d9280

Relationship Graph

Source Code

integration-tests/tests/sqlite/sqlite-proxy-batch.test.ts lines 136–212

class ServerSimulator {
	constructor(private db: BetterSqlite3.Database) {}

	async batch(queries: { sql: string; params: any[]; method: string }[]) {
		const results: { rows: any }[] = [];
		for (const query of queries) {
			const { method, sql, params } = query;

			if (method === 'run') {
				try {
					const result = this.db.prepare(sql).run(params);
					results.push(result as any);
				} catch (e: any) {
					return { error: e.message };
				}
			} else if (method === 'all' || method === 'values') {
				try {
					const rows = this.db.prepare(sql).raw().all(params);
					results.push({ rows: rows });
				} catch (e: any) {
					return { error: e.message };
				}
			} else if (method === 'get') {
				try {
					const row = this.db.prepare(sql).raw().get(params);
					results.push({ rows: row });
				} catch (e: any) {
					return { error: e.message };
				}
			} else {
				return { error: 'Unknown method value' };
			}
		}
		return results;
	}

	async query(sql: string, params: any[], method: string) {
		if (method === 'run') {
			try {
				const result = this.db.prepare(sql).run(params);
				return { data: result as any };
			} catch (e: any) {
				return { error: e.message };
			}
		} else if (method === 'all' || method === 'values') {
			try {
				const rows = this.db.prepare(sql).raw().all(params);
				return { data: rows };
			} catch (e: any) {
				return { error: e.message };
			}
		} else if (method === 'get') {
			try {
				const row = this.db.prepare(sql).raw().get(params);
				return { data: row };
			} catch (e: any) {
				return { error: e.message };
			}
		} else {
			return { error: 'Unknown method value' };
		}
	}

	migrations(queries: string[]) {
		this.db.exec('BEGIN');
		try {
			for (const query of queries) {
				this.db.exec(query);
			}
			this.db.exec('COMMIT');
		} catch {
			this.db.exec('ROLLBACK');
		}

		return {};
	}
}

Frequently Asked Questions

What is the ServerSimulator class?
ServerSimulator is a class in the drizzle-orm codebase, defined in integration-tests/tests/sqlite/sqlite-proxy-batch.test.ts.
Where is ServerSimulator defined?
ServerSimulator is defined in integration-tests/tests/sqlite/sqlite-proxy-batch.test.ts at line 136.

Analyze Your Own Codebase

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

Try Supermodel Free