Home / File/ driver.ts — drizzle-orm Source File

driver.ts — drizzle-orm Source File

Architecture documentation for driver.ts, a typescript file in the drizzle-orm codebase. 14 imports, 1 dependents.

File typescript DrizzleORM DatabaseDrivers 14 imports 1 dependents 4 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2["driver.ts"]
  fbb3fb4a_da8d_6a54_e5c6_4020c5a0f816["errors.ts"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> fbb3fb4a_da8d_6a54_e5c6_4020c5a0f816
  21afc23b_4e74_6442_f7c3_08020610b248["DrizzleError"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> 21afc23b_4e74_6442_f7c3_08020610b248
  4f23092f_3066_0d48_8396_c28751f25d01["session.ts"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> 4f23092f_3066_0d48_8396_c28751f25d01
  5a015744_9261_7efe_f6db_2bc9413b3057["MySql2Session"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> 5a015744_9261_7efe_f6db_2bc9413b3057
  e1b1f49f_839a_f414_dd91_58d1ba77668f["mysql2"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> e1b1f49f_839a_f414_dd91_58d1ba77668f
  a340f455_7575_91f4_791a_10cd9b9dba1a["promise"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> a340f455_7575_91f4_791a_10cd9b9dba1a
  363fdd67_2503_7ef7_e1f3_a1ef31694431["index.ts"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> 363fdd67_2503_7ef7_e1f3_a1ef31694431
  27705a9d_afe9_57dd_8c97_e52d8a67d426["entity.ts"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> 27705a9d_afe9_57dd_8c97_e52d8a67d426
  220c512d_350b_24bf_2142_53ec35a980ac["logger.ts"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> 220c512d_350b_24bf_2142_53ec35a980ac
  cffd352b_ee7e_3520_6232_dcb292268798["db.ts"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> cffd352b_ee7e_3520_6232_dcb292268798
  8e1e9852_05bf_563a_0455_d59c9d25a84e["dialect.ts"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> 8e1e9852_05bf_563a_0455_d59c9d25a84e
  41e092f8_b812_732d_b00f_7596b41fc839["session.ts"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> 41e092f8_b812_732d_b00f_7596b41fc839
  e4d6a0ab_9aa2_13a6_a2f1_58d94314c3f2["relations.ts"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> e4d6a0ab_9aa2_13a6_a2f1_58d94314c3f2
  ecce3253_1e75_a87f_27b3_ca87e81a3024["utils.ts"]
  9bd9488e_a0fa_b4b6_7790_4361efcb51f2 --> ecce3253_1e75_a87f_27b3_ca87e81a3024
  style 9bd9488e_a0fa_b4b6_7790_4361efcb51f2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { type Connection as CallbackConnection, createPool, type Pool as CallbackPool, type PoolOptions } from 'mysql2';
import type { Connection, Pool } from 'mysql2/promise';
import type { Cache } from '~/cache/core/index.ts';
import { entityKind } from '~/entity.ts';
import type { Logger } from '~/logger.ts';
import { DefaultLogger } from '~/logger.ts';
import { MySqlDatabase } from '~/mysql-core/db.ts';
import { MySqlDialect } from '~/mysql-core/dialect.ts';
import type { Mode } from '~/mysql-core/session.ts';
import {
	createTableRelationsHelpers,
	extractTablesRelationalConfig,
	type RelationalSchemaConfig,
	type TablesRelationalConfig,
} from '~/relations.ts';
import { type DrizzleConfig, isConfig } from '~/utils.ts';
import { DrizzleError } from '../errors.ts';
import type { MySql2Client, MySql2PreparedQueryHKT, MySql2QueryResultHKT } from './session.ts';
import { MySql2Session } from './session.ts';

export interface MySqlDriverOptions {
	logger?: Logger;
	cache?: Cache;
}

export class MySql2Driver {
	static readonly [entityKind]: string = 'MySql2Driver';

	constructor(
		private client: MySql2Client,
		private dialect: MySqlDialect,
		private options: MySqlDriverOptions = {},
	) {
	}

	createSession(
		schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,
		mode: Mode,
	): MySql2Session<Record<string, unknown>, TablesRelationalConfig> {
		return new MySql2Session(this.client, this.dialect, schema, {
			logger: this.options.logger,
			mode,
			cache: this.options.cache,
		});
	}
}

export { MySqlDatabase } from '~/mysql-core/db.ts';

export class MySql2Database<
	TSchema extends Record<string, unknown> = Record<string, never>,
> extends MySqlDatabase<MySql2QueryResultHKT, MySql2PreparedQueryHKT, TSchema> {
	static override readonly [entityKind]: string = 'MySql2Database';
}

export type MySql2DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> =
	& Omit<DrizzleConfig<TSchema>, 'schema'>
	& ({ schema: TSchema; mode: Mode } | { schema?: undefined; mode?: Mode });

function construct<
// ... (124 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does driver.ts do?
driver.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, DatabaseDrivers subdomain.
What functions are defined in driver.ts?
driver.ts defines 4 function(s): construct, drizzle, isCallbackClient, mock.
What does driver.ts depend on?
driver.ts imports 14 module(s): DrizzleError, MySql2Session, db.ts, dialect.ts, entity.ts, errors.ts, index.ts, logger.ts, and 6 more.
What files import driver.ts?
driver.ts is imported by 1 file(s): migrator.ts.
Where is driver.ts in the architecture?
driver.ts is located at drizzle-orm/src/mysql2/driver.ts (domain: DrizzleORM, subdomain: DatabaseDrivers, directory: drizzle-orm/src/mysql2).

Analyze Your Own Codebase

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

Try Supermodel Free