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
  c3d3ab17_c8ea_a11f_a388_84f5b4fdd4af["construct()"]
  c068d152_acc1_409d_348a_1545f08f9540["driver.ts"]
  c3d3ab17_c8ea_a11f_a388_84f5b4fdd4af -->|defined in| c068d152_acc1_409d_348a_1545f08f9540
  4bb0726b_313d_2342_50e0_30d0912b062e["drizzle()"]
  4bb0726b_313d_2342_50e0_30d0912b062e -->|calls| c3d3ab17_c8ea_a11f_a388_84f5b4fdd4af
  2ed7cbc7_2406_ed02_d286_3471a00a3a47["mock()"]
  2ed7cbc7_2406_ed02_d286_3471a00a3a47 -->|calls| c3d3ab17_c8ea_a11f_a388_84f5b4fdd4af
  style c3d3ab17_c8ea_a11f_a388_84f5b4fdd4af fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/postgres-js/driver.ts lines 22–68

function construct<TSchema extends Record<string, unknown> = Record<string, never>>(
	client: Sql,
	config: DrizzleConfig<TSchema> = {},
): PostgresJsDatabase<TSchema> & {
	$client: Sql;
} {
	const transparentParser = (val: any) => val;

	// Override postgres.js default date parsers: https://github.com/porsager/postgres/discussions/761
	for (const type of ['1184', '1082', '1083', '1114', '1182', '1185', '1115', '1231']) {
		client.options.parsers[type as any] = transparentParser;
		client.options.serializers[type as any] = transparentParser;
	}
	client.options.serializers['114'] = transparentParser;
	client.options.serializers['3802'] = transparentParser;

	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 session = new PostgresJsSession(client, dialect, schema, { logger, cache: config.cache });
	const db = new PostgresJsDatabase(dialect, session, schema as any) as PostgresJsDatabase<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/postgres-js/driver.ts.
Where is construct() defined?
construct() is defined in drizzle-orm/src/postgres-js/driver.ts at line 22.
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