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

construct() — drizzle-orm Function Reference

Architecture documentation for the construct() function in driver.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  811281dd_a2f3_96fc_b811_834647463172["construct()"]
  e9bcf6d5_8150_e6fa_afb8_81b1cb833dcc["driver.ts"]
  811281dd_a2f3_96fc_b811_834647463172 -->|defined in| e9bcf6d5_8150_e6fa_afb8_81b1cb833dcc
  09eb6778_0039_9908_9821_3b19813da94d["drizzle()"]
  09eb6778_0039_9908_9821_3b19813da94d -->|calls| 811281dd_a2f3_96fc_b811_834647463172
  05a9a17f_e637_e013_945c_d05975359265["mock()"]
  05a9a17f_e637_e013_945c_d05975359265 -->|calls| 811281dd_a2f3_96fc_b811_834647463172
  ea87ebcc_3564_7bc0_bd7e_b54d943bd335["isCallbackClient()"]
  811281dd_a2f3_96fc_b811_834647463172 -->|calls| ea87ebcc_3564_7bc0_bd7e_b54d943bd335
  bf19839a_7b72_47c7_69f8_34df5f0764c9["createSession()"]
  811281dd_a2f3_96fc_b811_834647463172 -->|calls| bf19839a_7b72_47c7_69f8_34df5f0764c9
  style 811281dd_a2f3_96fc_b811_834647463172 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/singlestore/driver.ts lines 61–106

function construct<
	TSchema extends Record<string, unknown> = Record<string, never>,
	TClient extends Pool | Connection | CallbackPool | CallbackConnection = CallbackPool,
>(
	client: TClient,
	config: SingleStoreDriverDrizzleConfig<TSchema> = {},
): SingleStoreDriverDatabase<TSchema> & {
	$client: AnySingleStoreDriverConnection extends TClient ? CallbackPool : TClient;
} {
	const dialect = new SingleStoreDialect({ casing: config.casing });
	let logger;
	if (config.logger === true) {
		logger = new DefaultLogger();
	} else if (config.logger !== false) {
		logger = config.logger;
	}

	const clientForInstance = isCallbackClient(client) ? client.promise() : client;

	let schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;
	if (config.schema) {
		const tablesConfig = extractTablesRelationalConfig(
			config.schema,
			createTableRelationsHelpers,
		);
		schema = {
			fullSchema: config.schema,
			schema: tablesConfig.tables,
			tableNamesMap: tablesConfig.tableNamesMap,
		};
	}

	const driver = new SingleStoreDriverDriver(clientForInstance as SingleStoreDriverClient, dialect, {
		logger,
		cache: config.cache,
	});
	const session = driver.createSession(schema);
	const db = new SingleStoreDriverDatabase(dialect, session, schema as any) as SingleStoreDriverDatabase<TSchema>;
	(<any> db).$client = client;
	(<any> db).$cache = config.cache;
	if ((<any> db).$cache) {
		(<any> db).$cache['invalidate'] = config.cache?.onMutate;
	}

	return db as any;
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does construct() do?
construct() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/singlestore/driver.ts.
Where is construct() defined?
construct() is defined in drizzle-orm/src/singlestore/driver.ts at line 61.
What does construct() call?
construct() calls 2 function(s): createSession, isCallbackClient.
What calls construct()?
construct() is called by 2 function(s): drizzle, mock.

Analyze Your Own Codebase

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

Try Supermodel Free