Home / Function/ prepareGelDB() — drizzle-orm Function Reference

prepareGelDB() — drizzle-orm Function Reference

Architecture documentation for the prepareGelDB() function in connections.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  9d143a2e_2710_c02a_6543_7b9163ac13ac["prepareGelDB()"]
  4e02c2bb_54a8_1500_813e_2cafd1ad4f59["connections.ts"]
  9d143a2e_2710_c02a_6543_7b9163ac13ac -->|defined in| 4e02c2bb_54a8_1500_813e_2cafd1ad4f59
  7aefe3aa_a868_e43f_09eb_fcf0004526d1["checkPackage()"]
  9d143a2e_2710_c02a_6543_7b9163ac13ac -->|calls| 7aefe3aa_a868_e43f_09eb_fcf0004526d1
  style 9d143a2e_2710_c02a_6543_7b9163ac13ac fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-kit/src/cli/connections.ts lines 536–617

export const prepareGelDB = async (
	credentials?: GelCredentials,
): Promise<
	DB & {
		packageName: 'gel';
		proxy: Proxy;
		transactionProxy: TransactionProxy;
	}
> => {
	if (await checkPackage('gel')) {
		const gel = await import('gel');

		let client: ReturnType<typeof gel.createClient>;
		if (!credentials) {
			client = gel.createClient();
			try {
				await client.querySQL(`select 1;`);
			} catch (error: any) {
				if (error instanceof gel.ClientConnectionError) {
					console.error(
						`It looks like you forgot to link the Gel project or provide the database credentials.
To link your project, please refer https://docs.geldata.com/reference/cli/gel_instance/gel_instance_link, or add the dbCredentials to your configuration file.`,
					);
					process.exit(1);
				}

				throw error;
			}
		} else if ('url' in credentials) {
			'tlsSecurity' in credentials
				? client = gel.createClient({ dsn: credentials.url, tlsSecurity: credentials.tlsSecurity, concurrency: 1 })
				: client = gel.createClient({ dsn: credentials.url, concurrency: 1 });
		} else {
			gel.createClient({ ...credentials, concurrency: 1 });
		}

		const query = async (sql: string, params?: any[]) => {
			const result = params?.length ? await client.querySQL(sql, params) : await client.querySQL(sql);
			return result as any[];
		};

		const proxy: Proxy = async (params: ProxyParams) => {
			const { method, mode, params: sqlParams, sql, typings } = params;

			let result: any[];
			switch (mode) {
				case 'array':
					result = sqlParams?.length
						? await client.withSQLRowMode('array').querySQL(sql, sqlParams)
						: await client.withSQLRowMode('array').querySQL(sql);
					break;
				case 'object':
					result = sqlParams?.length ? await client.querySQL(sql, sqlParams) : await client.querySQL(sql);
					break;
			}

			return result;
		};

		const transactionProxy: TransactionProxy = async (queries) => {
			const result: any[] = [];
			try {
				await client.transaction(async (tx) => {
					for (const query of queries) {
						const res = await tx.querySQL(query.sql);
						result.push(res);
					}
				});
			} catch (error) {
				result.push(error as Error);
			}
			return result;
		};

		return { packageName: 'gel', query, proxy, transactionProxy };
	}

	console.error(
		"To connect to gel database - please install 'edgedb' driver",
	);
	process.exit(1);

Domain

Subdomains

Frequently Asked Questions

What does prepareGelDB() do?
prepareGelDB() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/cli/connections.ts.
Where is prepareGelDB() defined?
prepareGelDB() is defined in drizzle-kit/src/cli/connections.ts at line 536.
What does prepareGelDB() call?
prepareGelDB() calls 1 function(s): checkPackage.

Analyze Your Own Codebase

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

Try Supermodel Free