Home / Class/ ServerSimulator Class — drizzle-orm Architecture

ServerSimulator Class — drizzle-orm Architecture

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

Entity Profile

Dependency Diagram

graph TD
  a76e119d_67cc_b66d_db8c_6162a7e33fe9["ServerSimulator"]
  f1e8cfe5_698a_f227_ec0b_55d2af2a5373["pg-proxy.test.ts"]
  a76e119d_67cc_b66d_db8c_6162a7e33fe9 -->|defined in| f1e8cfe5_698a_f227_ec0b_55d2af2a5373
  179d9c22_5f3f_ca23_7d20_3ba2f79808b0["constructor()"]
  a76e119d_67cc_b66d_db8c_6162a7e33fe9 -->|method| 179d9c22_5f3f_ca23_7d20_3ba2f79808b0
  22a61306_0206_917b_93a8_5c98e4450612["query()"]
  a76e119d_67cc_b66d_db8c_6162a7e33fe9 -->|method| 22a61306_0206_917b_93a8_5c98e4450612
  6ee33c4f_1a80_6e91_70bd_a9d7c04d0e79["migrations()"]
  a76e119d_67cc_b66d_db8c_6162a7e33fe9 -->|method| 6ee33c4f_1a80_6e91_70bd_a9d7c04d0e79

Relationship Graph

Source Code

integration-tests/tests/pg/pg-proxy.test.ts lines 14–72

class ServerSimulator {
	constructor(private db: pg.Client) {
		const { types } = pg;

		types.setTypeParser(types.builtins.TIMESTAMPTZ, (val) => val);
		types.setTypeParser(types.builtins.TIMESTAMP, (val) => val);
		types.setTypeParser(types.builtins.DATE, (val) => val);
		types.setTypeParser(types.builtins.INTERVAL, (val) => val);
		types.setTypeParser(1231, (val) => val);
		types.setTypeParser(1115, (val) => val);
		types.setTypeParser(1185, (val) => val);
		types.setTypeParser(1187, (val) => val);
		types.setTypeParser(1182, (val) => val);
	}

	async query(sql: string, params: any[], method: 'all' | 'execute') {
		if (method === 'all') {
			try {
				const result = await this.db.query({
					text: sql,
					values: params,
					rowMode: 'array',
				});

				return { data: result.rows as any };
			} catch (e: any) {
				return { error: e };
			}
		} else if (method === 'execute') {
			try {
				const result = await this.db.query({
					text: sql,
					values: params,
				});

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

	async migrations(queries: string[]) {
		await this.db.query('BEGIN');
		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/pg/pg-proxy.test.ts.
Where is ServerSimulator defined?
ServerSimulator is defined in integration-tests/tests/pg/pg-proxy.test.ts at line 14.

Analyze Your Own Codebase

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

Try Supermodel Free