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
  500ce032_ed8a_720f_f17a_8237f8fc187a["construct()"]
  59c162f8_73c0_8428_6675_320694336518["driver.ts"]
  500ce032_ed8a_720f_f17a_8237f8fc187a -->|defined in| 59c162f8_73c0_8428_6675_320694336518
  a78183a3_6dd7_afcd_42a4_8db93d42693e["drizzle()"]
  a78183a3_6dd7_afcd_42a4_8db93d42693e -->|calls| 500ce032_ed8a_720f_f17a_8237f8fc187a
  b32cf2bf_6087_d148_c1d9_521a6670a73e["mock()"]
  b32cf2bf_6087_d148_c1d9_521a6670a73e -->|calls| 500ce032_ed8a_720f_f17a_8237f8fc187a
  b29a7944_45a2_47f0_383e_b204024ccb48["createSession()"]
  500ce032_ed8a_720f_f17a_8237f8fc187a -->|calls| b29a7944_45a2_47f0_383e_b204024ccb48
  style 500ce032_ed8a_720f_f17a_8237f8fc187a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/neon-serverless/driver.ts lines 49–89

function construct<
	TSchema extends Record<string, unknown> = Record<string, never>,
	TClient extends NeonClient = NeonClient,
>(
	client: TClient,
	config: DrizzleConfig<TSchema> = {},
): NeonDatabase<TSchema> & {
	$client: NeonClient extends TClient ? Pool : TClient;
} {
	const dialect = new PgDialect({ casing: config.casing });
	let logger;
	if (config.logger === true) {
		logger = new DefaultLogger();
	} else if (config.logger !== false) {
		logger = config.logger;
	}

	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 NeonDriver(client, dialect, { logger, cache: config.cache });
	const session = driver.createSession(schema);
	const db = new NeonDatabase(dialect, session, schema as any) as NeonDatabase<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/neon-serverless/driver.ts.
Where is construct() defined?
construct() is defined in drizzle-orm/src/neon-serverless/driver.ts at line 49.
What does construct() call?
construct() calls 1 function(s): createSession.
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