Skip to main content
Module

x/typeorm/src/driver/Driver.ts>Driver

Forked from https://github.com/typeorm/typeorm
Latest
interface Driver
import { type Driver } from "https://deno.land/x/typeorm@v0.2.23-rc10/src/driver/Driver.ts";

Driver organizes TypeORM communication with specific database management system.

Properties

Connection options.

optional
database: string

Master database used to perform all write queries.

todo: probably move into query runner.

isReplicated: boolean

Indicates if replication is enabled.

treeSupport: boolean

Indicates if tree tables are supported by this driver.

supportedDataTypes: ColumnType[]

Gets list of supported column data types by a driver.

dataTypeDefaults: DataTypeDefaults

Default values of length, precision and scale depends on column data type. Used in the cases when length/precision/scale is not specified by user.

spatialTypes: ColumnType[]

Gets list of spatial column data types.

withLengthColumnTypes: ColumnType[]

Gets list of column data types that support length by a driver.

withPrecisionColumnTypes: ColumnType[]

Gets list of column data types that support precision by a driver.

withScaleColumnTypes: ColumnType[]

Gets list of column data types that support scale by a driver.

mappedDataTypes: MappedColumnTypes

Orm has special columns and we need to know what database column types should be for those types. Column types are driver dependant.

optional
maxAliasLength: number

Max length allowed by the DBMS for aliases (execution of queries).

Methods

connect(): Promise<void>

Performs connection to the database. Depend on driver type it may create a connection pool.

afterConnect(): Promise<void>

Makes any action after connection (e.g. create extensions in Postgres driver).

disconnect(): Promise<void>

Closes connection with database and releases all resources.

createSchemaBuilder(): SchemaBuilder

Synchronizes database schema (creates tables, indices, etc).

createQueryRunner(mode: "master" | "slave"): QueryRunner

Creates a query runner used for common queries.

escapeQueryWithParameters(
sql: string,
parameters: ObjectLiteral,
nativeParameters: ObjectLiteral,
): [string, any[]]

Replaces parameters in the given sql with special escaping character and an array of parameter names to be passed to a query.

escape(name: string): string

Escapes a table name, column name or an alias.

todo: probably escape should be able to handle dots in the names and automatically escape them

buildTableName(
tableName: string,
schema?: string,
database?: string,
): string

Build full table name with database name, schema name and table name. E.g. "myDB"."mySchema"."myTable"

preparePersistentValue(value: any, column: ColumnMetadata): any

Prepares given value to a value to be persisted, based on its column type and metadata.

prepareHydratedValue(value: any, column: ColumnMetadata): any

Prepares given value to a value to be persisted, based on its column type.

normalizeType(column: { type?: ColumnType | string; length?: number | string; precision?: number | null; scale?: number; isArray?: boolean; }): string

Transforms type of the given column to a database column type.

normalizeDefault(columnMetadata: ColumnMetadata): string

Normalizes "default" value of the column.

normalizeIsUnique(column: ColumnMetadata): boolean

Normalizes "isUnique" value of the column.

getColumnLength(column: ColumnMetadata): string

Calculates column length taking into account the default length values.

createFullType(column: TableColumn): string

Normalizes "default" value of the column.

obtainMasterConnection(): Promise<any>

Obtains a new database connection to a master server. Used for replication. If replication is not setup then returns default connection's database connection.

obtainSlaveConnection(): Promise<any>

Obtains a new database connection to a slave server. Used for replication. If replication is not setup then returns master (default) connection's database connection.

createGeneratedMap(metadata: EntityMetadata, insertResult: any): ObjectLiteral | undefined

Creates generated map of values generated or returned by database after INSERT query.

findChangedColumns(tableColumns: TableColumn[], columnMetadatas: ColumnMetadata[]): ColumnMetadata[]

Differentiate columns of this table and columns from the given column metadatas columns and returns only changed.

isReturningSqlSupported(): boolean

Returns true if driver supports RETURNING / OUTPUT statement.

isUUIDGenerationSupported(): boolean

Returns true if driver supports uuid values generation on its own.

createParameter(parameterName: string, index: number): string

Creates an escaped parameter.