Skip to main content
Version: 4.5

Class: DatabaseDriver<C>#

core.DatabaseDriver

Type parameters#

NameType
CConnection

Hierarchy#

Implements#

Constructors#

constructor#

+ Protectednew DatabaseDriver<C>(config: Configuration<IDatabaseDriver<Connection>>, dependencies: string[]): DatabaseDriver<C>

Type parameters:#

NameType
CConnection<C>

Parameters:#

NameType
configConfiguration<IDatabaseDriver<Connection>>
dependenciesstring[]

Returns: DatabaseDriver<C>

Defined in: packages/core/src/drivers/DatabaseDriver.ts:22

Properties#

[EntityManagerType]#

[EntityManagerType]: EntityManager<DatabaseDriver<C>>

Implementation of: IDatabaseDriver.[EntityManagerType]

Defined in: packages/core/src/drivers/DatabaseDriver.ts:15


comparator#

Protected comparator: EntityComparator

Defined in: packages/core/src/drivers/DatabaseDriver.ts:21


config#

Protected Readonly config: Configuration<IDatabaseDriver<Connection>>


connection#

Protected Readonly connection: C

Defined in: packages/core/src/drivers/DatabaseDriver.ts:17


dependencies#

Protected Readonly dependencies: string[]


logger#

Protected Readonly logger: Logger

Defined in: packages/core/src/drivers/DatabaseDriver.ts:20


metadata#

Protected metadata: MetadataStorage

Defined in: packages/core/src/drivers/DatabaseDriver.ts:22


platform#

Protected Readonly platform: Platform

Defined in: packages/core/src/drivers/DatabaseDriver.ts:19


replicas#

Protected Readonly replicas: C[]

Defined in: packages/core/src/drivers/DatabaseDriver.ts:18

Methods#

aggregate#

aggregate(entityName: string, pipeline: any[]): Promise<any[]>

Parameters:#

NameType
entityNamestring
pipelineany[]

Returns: Promise<any[]>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:49


close#

close(force?: boolean): Promise<void>

Parameters:#

NameType
force?boolean

Returns: Promise<void>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:93


connect#

connect(): Promise<C>

Returns: Promise<C>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:71


convertException#

convertException(exception: Error): DriverException

Converts native db errors to standardized driver exceptions

Parameters:#

NameType
exceptionError

Returns: DriverException

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:254


count#

Abstractcount<T>(entityName: string, where: FilterQuery<T>, options?: CountOptions<T>, ctx?: any): Promise<number>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
whereFilterQuery<T>
options?CountOptions<T>
ctx?any

Returns: Promise<number>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:43


createEntityManager#

createEntityManager<D>(useContext?: boolean): D[typeof EntityManagerType]

Type parameters:#

NameTypeDefault
DIDatabaseDriver<Connection, D>IDatabaseDriver<Connection>

Parameters:#

NameType
useContext?boolean

Returns: D[typeof EntityManagerType]

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:45


createReplicas#

ProtectedcreateReplicas(cb: (c: ConnectionOptions) => C): C[]

Parameters:#

NameType
cb(c: ConnectionOptions) => C

Returns: C[]

Defined in: packages/core/src/drivers/DatabaseDriver.ts:215


ensureIndexes#

ensureIndexes(): Promise<void>

Returns: Promise<void>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:127


find#

Abstractfind<T>(entityName: string, where: FilterQuery<T>, options?: FindOptions<T, readonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>>, ctx?: any): Promise<EntityData<T>[]>

Finds selection of entities

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
whereFilterQuery<T>
options?FindOptions<T, readonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>>
ctx?any

Returns: Promise<EntityData<T>[]>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:27


findOne#

AbstractfindOne<T>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, readonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>>, ctx?: any): Promise<null | EntityData<T>>

Finds single entity (table row, document)

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
whereFilterQuery<T>
options?FindOneOptions<T, readonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>>
ctx?any

Returns: Promise<null | EntityData<T>>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:29


getConnection#

getConnection(type?: read | write): C

Parameters:#

NameTypeDefault value
typeread | write'write'

Returns: C

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:83


getDependencies#

getDependencies(): string[]

Returns name of the underlying database dependencies (e.g. mongodb or mysql2) for SQL drivers it also returns knex in the array as connectors are not used directly there

Returns: string[]

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:123


getPivotInverseProperty#

ProtectedgetPivotInverseProperty(prop: EntityProperty<any>): EntityProperty<any>

Parameters:#

NameType
propEntityProperty<any>

Returns: EntityProperty<any>

Defined in: packages/core/src/drivers/DatabaseDriver.ts:200


getPivotOrderBy#

ProtectedgetPivotOrderBy(prop: EntityProperty<any>, orderBy?: QueryOrderMap): QueryOrderMap

Parameters:#

NameType
propEntityProperty<any>
orderBy?QueryOrderMap

Returns: QueryOrderMap

Defined in: packages/core/src/drivers/DatabaseDriver.ts:179


getPlatform#

getPlatform(): Platform

Returns: Platform

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:108


getPrimaryKeyFields#

ProtectedgetPrimaryKeyFields(entityName: string): string[]

Parameters:#

NameType
entityNamestring

Returns: string[]

Defined in: packages/core/src/drivers/DatabaseDriver.ts:195


inlineEmbeddables#

ProtectedinlineEmbeddables<T>(meta: EntityMetadata<T>, data: T, where?: boolean): void

Type parameters:#

Name
T

Parameters:#

NameType
metaEntityMetadata<T>
dataT
where?boolean

Returns: void

Defined in: packages/core/src/drivers/DatabaseDriver.ts:131


loadFromPivotTable#

loadFromPivotTable<T, O>(prop: EntityProperty<any>, owners: Primary<O>[][], where?: FilterQuery<T>, orderBy?: QueryOrderMap, ctx?: any, options?: FindOptions<T, readonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>>): Promise<Dictionary<T[]>>

When driver uses pivot tables for M:N, this method will load identifiers for given collections from them

Type parameters:#

NameType
TAnyEntity<T>
OAnyEntity<O>

Parameters:#

NameType
propEntityProperty<any>
ownersPrimary<O>[][]
where?FilterQuery<T>
orderBy?QueryOrderMap
ctx?any
options?FindOptions<T, readonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>>

Returns: Promise<Dictionary<T[]>>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:53


lockPessimistic#

lockPessimistic<T>(entity: T, mode: LockMode, ctx?: any): Promise<void>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityT
modeLockMode
ctx?any

Returns: Promise<void>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:228


mapResult#

mapResult<T>(result: EntityData<T>, meta: EntityMetadata<T>, populate?: PopulateOptions<T>[]): null | EntityData<T>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
resultEntityData<T>
metaEntityMetadata<T>
populatePopulateOptions<T>[]

Returns: null | EntityData<T>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:63


nativeDelete#

AbstractnativeDelete<T>(entityName: string, where: FilterQuery<T>, ctx?: any): Promise<QueryResult>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
whereFilterQuery<T>
ctx?any

Returns: Promise<QueryResult>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:41


nativeInsert#

AbstractnativeInsert<T>(entityName: string, data: EntityData<T>, ctx?: any, convertCustomTypes?: boolean): Promise<QueryResult>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
dataEntityData<T>
ctx?any
convertCustomTypes?boolean

Returns: Promise<QueryResult>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:31


nativeInsertMany#

AbstractnativeInsertMany<T>(entityName: string, data: EntityData<T>[], ctx?: any, processCollections?: boolean, convertCustomTypes?: boolean): Promise<QueryResult>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
dataEntityData<T>[]
ctx?any
processCollections?boolean
convertCustomTypes?boolean

Returns: Promise<QueryResult>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:33


nativeUpdate#

AbstractnativeUpdate<T>(entityName: string, where: FilterQuery<T>, data: EntityData<T>, ctx?: any, convertCustomTypes?: boolean): Promise<QueryResult>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
whereFilterQuery<T>
dataEntityData<T>
ctx?any
convertCustomTypes?boolean

Returns: Promise<QueryResult>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:35


nativeUpdateMany#

nativeUpdateMany<T>(entityName: string, where: FilterQuery<T>[], data: EntityData<T>[], ctx?: any, processCollections?: boolean, convertCustomTypes?: boolean): Promise<QueryResult>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
entityNamestring
whereFilterQuery<T>[]
dataEntityData<T>[]
ctx?any
processCollections?boolean
convertCustomTypes?boolean

Returns: Promise<QueryResult>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:37


reconnect#

reconnect(): Promise<C>

Returns: Promise<C>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:78


rethrow#

Protectedrethrow<T>(promise: Promise<T>): Promise<T>

Type parameters:#

Name
T

Parameters:#

NameType
promisePromise<T>

Returns: Promise<T>

Defined in: packages/core/src/drivers/DatabaseDriver.ts:262


setMetadata#

setMetadata(metadata: MetadataStorage): void

Parameters:#

NameType
metadataMetadataStorage

Returns: void

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:112


shouldHaveColumn#

shouldHaveColumn<T>(prop: EntityProperty<T>, populate: PopulateOptions<T>[], includeFormulas?: boolean): boolean

internal

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameTypeDefault value
propEntityProperty<T>-
populatePopulateOptions<T>[]-
includeFormulasbooleantrue

Returns: boolean

Defined in: packages/core/src/drivers/DatabaseDriver.ts:235


syncCollection#

syncCollection<T, O>(coll: Collection<T, O>, ctx?: any): Promise<void>

Type parameters:#

NameType
TAnyEntity<T>
OAnyEntity<O>

Parameters:#

NameType
collCollection<T, O>
ctx?any

Returns: Promise<void>

Implementation of: IDatabaseDriver

Defined in: packages/core/src/drivers/DatabaseDriver.ts:57

Last updated on by Martin Adámek