Home / Class/ ServerSimulator Class — drizzle-orm Architecture

ServerSimulator Class — drizzle-orm Architecture

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

Entity Profile

Dependency Diagram

graph TD
  75656cb7_cdf7_c139_423d_32a1503bf89d["ServerSimulator"]
  5852db24_8352_dcff_7363_b8ff5c9f3d7f["mysql-proxy.test.ts"]
  75656cb7_cdf7_c139_423d_32a1503bf89d -->|defined in| 5852db24_8352_dcff_7363_b8ff5c9f3d7f
  68a1ee6f_bd39_a9fe_a873_0f4e967ee023["constructor()"]
  75656cb7_cdf7_c139_423d_32a1503bf89d -->|method| 68a1ee6f_bd39_a9fe_a873_0f4e967ee023
  94e5d831_42a0_71bd_829a_0c755b04cd61["query()"]
  75656cb7_cdf7_c139_423d_32a1503bf89d -->|method| 94e5d831_42a0_71bd_829a_0c755b04cd61
  8f85f40c_ece2_3507_0e52_667752a58627["migrations()"]
  75656cb7_cdf7_c139_423d_32a1503bf89d -->|method| 8f85f40c_ece2_3507_0e52_667752a58627

Relationship Graph

Source Code

integration-tests/tests/mysql/mysql-proxy.test.ts lines 12–70

class ServerSimulator {
	constructor(private db: mysql.Connection) {}

	async query(sql: string, params: any[], method: 'all' | 'execute') {
		if (method === 'all') {
			try {
				const result = await this.db.query({
					sql,
					values: params,
					rowsAsArray: true,
					typeCast: function(field: any, next: any) {
						if (field.type === 'TIMESTAMP' || field.type === 'DATETIME' || field.type === 'DATE') {
							return field.string();
						}
						return next();
					},
				});

				return { data: result[0] as any };
			} catch (e: any) {
				return { error: e };
			}
		} else if (method === 'execute') {
			try {
				const result = await this.db.query({
					sql,
					values: params,
					typeCast: function(field: any, next: any) {
						if (field.type === 'TIMESTAMP' || field.type === 'DATETIME' || field.type === 'DATE') {
							return field.string();
						}
						return next();
					},
				});

				return { data: result as any };
			} catch (e: any) {
				return { error: e };
			}
		} else {
			return { error: 'Unknown method value' };
		}
	}

	async migrations(queries: string[]) {
		await this.db.query('START TRANSACTION');
		try {
			for (const query of queries) {
				await this.db.query(query);
			}
			await this.db.query('COMMIT');
		} catch (e) {
			await this.db.query('ROLLBACK');
			throw e;
		}

		return {};
	}
}

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free