Skip to content

Class: Database ​

A database connection of its own: a transient provider wrapping a TypeORM DataSource, with the API of the Database component of lakutata/com/database.

Register it in the providers of the application options with buildDatabaseOptions. Each resolution (@Inject('reports'), getObject('reports')) creates a new instance, even within one scope: it opens its own connection (its own pool) while it is created, and closes it when it is destroyed with the object or the container which created it. It suits a short use (a job, a script, a tenant database); the requests of a busy application share the Database component instead. A connection failure rejects its creation with the driver error.

The entities of its entities option are added to the entities of its connection options. Its where conditions leave out their properties whose value is null or undefined, as the ones of the Database component (TypeORM 1 throws on them by default), unless the options set invalidWhereValuesBehavior.

Example ​

typescript
import {Application} from 'lakutata'
import {buildDatabaseOptions, Database} from 'lakutata/provider/database'
import {Column, Entity, PrimaryGeneratedColumn} from 'lakutata/decorator/orm'

@Entity()
class Report {
    @PrimaryGeneratedColumn()
    public id: number

    @Column('text')
    public content: string
}

Application
    .run(() => ({
        id: 'com.example.reports',
        name: 'Reports',
        providers: {
            reports: {
                ...buildDatabaseOptions({type: 'postgres', url: 'postgres://postgres:secret@localhost:5432/reports', synchronize: true}),
                entities: [Report]
            }
        }
    }))
    .onLaunched(async (app: Application): Promise<void> => {
        //A connection opened for this use, closed with the application
        const database: Database = await app.getObject('reports')
        await database.transaction(async (manager): Promise<void> => {
            await manager.save(Report, {content: 'Daily report'})
        })
        console.log(await database.getRepository(Report).count())
    })

Extends ​

Constructors ​

Constructor ​

new Database(cradleProxy): Database

Called by the container only: an object is created through a container (see the class description), never with new.

Parameters ​

cradleProxy ​

Record<string | symbol, any>

The container's resolution proxy.

Returns ​

Database

Inherited from ​

Provider.constructor

Properties ​

constructor ​

constructor: Function

The initial value of Object.prototype.constructor is the standard built-in Object constructor.

Inherited from ​

Provider.constructor


migrationExecutor ​

static migrationExecutor: () => Promise<typeof Provider>

Load the provider running, reverting or showing the migrations of the database. The application calls it when it is started with MIGRATION_RUN, MIGRATION_REVERT or MIGRATION_SHOW: the applications do not call it.

Returns ​

Promise<typeof Provider>

The migration executor provider class.


migrationGenerator ​

static migrationGenerator: () => Promise<typeof Provider>

Load the provider generating the migrations of the database. The application calls it when it is started with MIGRATION_GENERATE: the applications do not call it.

Returns ​

Promise<typeof Provider>

The migration generator provider class.

Accessors ​

$id ​

Get Signature ​

get $id(): string | symbol

The name the object was registered under (its key in the module options), or a symbol of its class for an object registered by its class or built without registration.

Returns ​

string | symbol

Inherited from ​

Provider.$id


$symbol ​

Get Signature ​

get $symbol(): symbol

A symbol unique to the instance (made from its $uuid), created on first read.

Returns ​

symbol

Inherited from ​

Provider.$symbol


$uuid ​

Get Signature ​

get $uuid(): string

A random UUID identifying the instance.

Returns ​

string

Inherited from ​

Provider.$uuid


className ​

Get Signature ​

get static className(): string

The name of the class.

Returns ​

string

Inherited from ​

Provider.className


className ​

Get Signature ​

get className(): string

The name of the object's class.

Returns ​

string

Inherited from ​

Provider.className


driver ​

Get Signature ​

get driver(): Driver

The TypeORM driver of the connection (PostgreSQL, MySQL, SQLite…).

Returns ​

Driver


entityMetadatas ​

Get Signature ​

get entityMetadatas(): EntityMetadata[]

The metadata of every entity registered on the connection.

Returns ​

EntityMetadata[]


entityMetadatasMap ​

Get Signature ​

get entityMetadatasMap(): Map<EntityTarget<any>, EntityMetadata>

The metadata of every entity registered on the connection, by entity target (class, name or schema): the same as Database.entityMetadatas, for fast lookups.

Returns ​

Map<EntityTarget<any>, EntityMetadata>


manager ​

Get Signature ​

get manager(): EntityManager

The entity manager of the connection: the TypeORM operations on any entity (find, save, delete…) outside a transaction.

Returns ​

EntityManager


namingStrategy ​

Get Signature ​

get namingStrategy(): NamingStrategyInterface

The naming strategy of the connection, which names the tables, the columns and the constraints of the entities.

Default ​

TypeORM's DefaultNamingStrategy, unless the options set namingStrategy

Returns ​

NamingStrategyInterface

Set Signature ​

set namingStrategy(instance): void

Replace the naming strategy of the connection. The names of the tables, the columns and the constraints of the entities are built when it connects, with the namingStrategy of the connection options: they are not renamed, only the names built afterwards (the constraints a query runner creates unnamed) use this one. To name the entities, set the namingStrategy option.

Parameters ​
instance ​

NamingStrategyInterface

The naming strategy.

Returns ​

void


queryResultCache ​

Get Signature ​

get queryResultCache(): QueryResultCache | undefined

The query result cache of the connection, undefined unless the options enable cache.

Returns ​

QueryResultCache | undefined


subscribers ​

Get Signature ​

get subscribers(): EntitySubscriberInterface<any>[]

The entity subscribers registered on the connection (the subscribers of the options).

Returns ​

EntitySubscriberInterface<any>[]

Methods ​

[asyncDispose]() ​

[asyncDispose](): Promise<void>

Dispose the object at the end of an await using block, as BaseObject.dispose.

Returns ​

Promise<void>

Resolves once the object is destroyed.

Inherited from ​

Provider.[asyncDispose]


acceptsOption() ​

static acceptsOption(name, value): boolean

Whether the class accepts an option which is not one of its @Configurable properties (an option it reads with getConfigurableRecords()): the modules check the options of the objects they declare and warn of the options the classes do not accept. Override it in the classes reading options without configurable properties.

Parameters ​

name ​

string

The option name.

value ​

unknown

The option value.

Returns ​

boolean

true when the option is accepted; false by default.

Inherited from ​

Provider.acceptsOption


assign() ​

Call Signature ​

static assign<T, U>(target, source): T & U

Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

Type Parameters ​
T ​

T extends object

U ​

U

Parameters ​
target ​

T

The target object to copy to.

source ​

U

The source object from which to copy properties.

Returns ​

T & U

Inherited from ​

Provider.assign

Call Signature ​

static assign<T, U, V>(target, source1, source2): T & U & V

Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

Type Parameters ​
T ​

T extends object

U ​

U

V ​

V

Parameters ​
target ​

T

The target object to copy to.

source1 ​

U

The first source object from which to copy properties.

source2 ​

V

The second source object from which to copy properties.

Returns ​

T & U & V

Inherited from ​

Provider.assign

Call Signature ​

static assign<T, U, V, W>(target, source1, source2, source3): T & U & V & W

Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

Type Parameters ​
T ​

T extends object

U ​

U

V ​

V

W ​

W

Parameters ​
target ​

T

The target object to copy to.

source1 ​

U

The first source object from which to copy properties.

source2 ​

V

The second source object from which to copy properties.

source3 ​

W

The third source object from which to copy properties.

Returns ​

T & U & V & W

Inherited from ​

Provider.assign

Call Signature ​

static assign(target, ...sources): any

Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

Parameters ​
target ​

object

The target object to copy to.

sources ​

...any[]

One or more source objects from which to copy properties

Returns ​

any

Inherited from ​

Provider.assign


create() ​

Call Signature ​

static create(o): any

Creates an object that has the specified prototype or that has null prototype.

Parameters ​
o ​

object | null

Object to use as a prototype. May be null.

Returns ​

any

Inherited from ​

Provider.create

Call Signature ​

static create(o, properties): any

Creates an object that has the specified prototype, and that optionally contains specified properties.

Parameters ​
o ​

object | null

Object to use as a prototype. May be null

properties ​

PropertyDescriptorMap & ThisType<any>

JavaScript object that contains one or more property descriptors.

Returns ​

any

Inherited from ​

Provider.create


createEntityManager() ​

createEntityManager(queryRunner?): EntityManager

Create an entity manager on the connection, bound to a query runner when given (its operations then run on the runner's connection and transaction).

Parameters ​

queryRunner? ​

QueryRunner

The query runner the manager uses, a connection of the pool per operation otherwise.

Returns ​

EntityManager

The entity manager.


createQueryBuilder() ​

Call Signature ​

createQueryBuilder<Entity>(entityClass, alias, queryRunner?): SelectQueryBuilder<Entity>

Create a query builder selecting an entity.

Type Parameters ​
Entity ​

Entity extends ObjectLiteral

Parameters ​
entityClass ​

EntityTarget<Entity>

The entity class, its name, or its EntitySchema.

alias ​

string

The alias of the entity in the query ('user' in user.name).

queryRunner? ​

QueryRunner

The query runner to run the query on, a connection of the pool otherwise.

Returns ​

SelectQueryBuilder<Entity>

The query builder, selecting the entity from its table.

Throws ​

When the entity is not registered.

Throws ​

On a MongoDB connection, which has no query builder.

Call Signature ​

createQueryBuilder(queryRunner?): SelectQueryBuilder<any>

Create an empty query builder, its selection and source set by its select() and from().

Parameters ​
queryRunner? ​

QueryRunner

The query runner to run the query on, a connection of the pool otherwise.

Returns ​

SelectQueryBuilder<any>

The query builder.

Throws ​

On a MongoDB connection, which has no query builder.


createQueryRunner() ​

createQueryRunner(mode?): QueryRunner

Create a query runner: one connection taken from the pool, to run several queries on the same connection and control its transaction by hand (connect(), startTransaction(), commitTransaction(), rollbackTransaction()). The caller must release() it, or the connection stays taken.

Parameters ​

mode? ​

ReplicationMode

With replication, 'master' (the default) for the writes, 'slave' for the reads on a replica.

Returns ​

QueryRunner

The query runner, not connected until its first query or connect().


defineProperties() ​

static defineProperties<T>(o, properties): T

Adds one or more properties to an object, and/or modifies attributes of existing properties.

Type Parameters ​

T ​

T

Parameters ​

o ​

T

Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object.

properties ​

PropertyDescriptorMap & ThisType<any>

JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property.

Returns ​

T

Inherited from ​

Provider.defineProperties


defineProperty() ​

static defineProperty<T>(o, p, attributes): T

Adds a property to an object, or modifies attributes of an existing property.

Type Parameters ​

T ​

T

Parameters ​

o ​

T

Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object.

p ​

PropertyKey

The property name.

attributes ​

PropertyDescriptor & ThisType<any>

Descriptor for the property. It can be for a data property or an accessor property.

Returns ​

T

Inherited from ​

Provider.defineProperty


dispose() ​

dispose(): Promise<void>

Destroy the object: its beforeDestroy(), the objects it created, then its destroy(). Calling it more than once destroys once. A disposed singleton or scoped object is dropped from its container, which creates a new one on the next request. Using a destroyed object (getObject(), buildObject()) throws an ObjectDestroyedException.

Returns ​

Promise<void>

Resolves once the object is destroyed.

Throws ​

The error of the object's own beforeDestroy() or destroy() (an AggregateError when several fail); the errors of the objects it created are reported through the application's logger instead.

Inherited from ​

Provider.dispose


entries() ​

Call Signature ​

static entries<T>(o): [string, T][]

Returns an array of key/values of the enumerable own properties of an object

Type Parameters ​
T ​

T

Parameters ​
o ​

{[s: string]: T; } | ArrayLike<T>

Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

Returns ​

[string, T][]

Inherited from ​

Provider.entries

Call Signature ​

static entries(o): [string, any][]

Returns an array of key/values of the enumerable own properties of an object

Parameters ​
o ​

{ }

Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

Returns ​

[string, any][]

Inherited from ​

Provider.entries


freeze() ​

Call Signature ​

static freeze<T>(f): T

Prevents the modification of existing property attributes and values, and prevents the addition of new properties.

Type Parameters ​
T ​

T extends Function

Parameters ​
f ​

T

Object on which to lock the attributes.

Returns ​

T

Inherited from ​

Provider.freeze

Call Signature ​

static freeze<T, U>(o): Readonly<T>

Prevents the modification of existing property attributes and values, and prevents the addition of new properties.

Type Parameters ​
T ​

T extends object

U ​

U extends string | number | bigint | boolean | symbol

Parameters ​
o ​

T

Object on which to lock the attributes.

Returns ​

Readonly<T>

Inherited from ​

Provider.freeze

Call Signature ​

static freeze<T>(o): Readonly<T>

Prevents the modification of existing property attributes and values, and prevents the addition of new properties.

Type Parameters ​
T ​

T

Parameters ​
o ​

T

Object on which to lock the attributes.

Returns ​

Readonly<T>

Inherited from ​

Provider.freeze


fromEntries() ​

Call Signature ​

static fromEntries<T>(entries): object

Returns an object created by key-value entries for properties and methods

Type Parameters ​
T ​

T = any

Parameters ​
entries ​

Iterable<readonly [PropertyKey, T]>

An iterable object that contains key-value entries for properties and methods.

Returns ​

object

Inherited from ​

Provider.fromEntries

Call Signature ​

static fromEntries(entries): any

Returns an object created by key-value entries for properties and methods

Parameters ​
entries ​

Iterable<readonly any[]>

An iterable object that contains key-value entries for properties and methods.

Returns ​

any

Inherited from ​

Provider.fromEntries


getManyToManyMetadata() ​

getManyToManyMetadata(entityTarget, relationPropertyPath): EntityMetadata | undefined

The metadata of the junction table of a many-to-many relation.

Parameters ​

entityTarget ​

EntityTarget<any>

The entity owning the relation.

relationPropertyPath ​

string

The property of the relation ('tags', or a path such as 'profile.tags').

Returns ​

EntityMetadata | undefined

The metadata of the junction table.

Throws ​

When the entity is not registered.

Throws ​

When the entity has no such relation, or the relation is not a many-to-many one.


getMetadata() ​

getMetadata(target): EntityMetadata

The metadata of a registered entity: its table, columns, relations…

Parameters ​

target ​

EntityTarget<any>

The entity class, its name, or its table name.

Returns ​

EntityMetadata

The metadata of the entity.

Throws ​

When the entity is not registered on the connection.


getMethod() ​

getMethod(name, throwExceptionIfNotFound?): (...args) => any

Get a method bound to the object, to call it by name.

Parameters ​

name ​

string | symbol

The method name or symbol.

throwExceptionIfNotFound? ​

boolean

Throw when the method does not exist, instead of returning a function doing nothing; false by default.

Returns ​

The bound method, or a function doing nothing (returning undefined) when it does not exist.

(...args) => any

Throws ​

When the method does not exist and throwExceptionIfNotFound is true.

Inherited from ​

Provider.getMethod


getMongoRepository() ​

getMongoRepository<Entity>(target): MongoRepository<Entity>

The MongoDB repository of an entity: the repository operations plus the MongoDB ones (aggregate, bulkWrite…).

Type Parameters ​

Entity ​

Entity extends ObjectLiteral

Parameters ​

target ​

EntityTarget<Entity>

The entity class, or its name.

Returns ​

MongoRepository<Entity>

The MongoDB repository of the entity.

Throws ​

When the connection is not a MongoDB one.


getOwnPropertyDescriptor() ​

static getOwnPropertyDescriptor(o, p): PropertyDescriptor | undefined

Gets the own property descriptor of the specified object. An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.

Parameters ​

o ​

any

Object that contains the property.

p ​

PropertyKey

Name of the property.

Returns ​

PropertyDescriptor | undefined

Inherited from ​

Provider.getOwnPropertyDescriptor


getOwnPropertyDescriptors() ​

static getOwnPropertyDescriptors<T>(o): { [P in string | number | symbol]: TypedPropertyDescriptor<T[P]> } & object

Returns an object containing all own property descriptors of an object

Type Parameters ​

T ​

T

Parameters ​

o ​

T

Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

Returns ​

{ [P in string | number | symbol]: TypedPropertyDescriptor<T[P]> } & object

Inherited from ​

Provider.getOwnPropertyDescriptors


getOwnPropertyNames() ​

static getOwnPropertyNames(o): string[]

Returns the names of the own properties of an object. The own properties of an object are those that are defined directly on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions.

Parameters ​

o ​

any

Object that contains the own properties.

Returns ​

string[]

Inherited from ​

Provider.getOwnPropertyNames


getOwnPropertySymbols() ​

static getOwnPropertySymbols(o): symbol[]

Returns an array of all symbol properties found directly on object o.

Parameters ​

o ​

any

Object to retrieve the symbols from.

Returns ​

symbol[]

Inherited from ​

Provider.getOwnPropertySymbols


getProperty() ​

getProperty<T>(propertyKey, defaultValue?): T

Read an own property of the object.

Type Parameters ​

T ​

T = any

Parameters ​

propertyKey ​

string

The property name.

defaultValue? ​

T

The value returned when the object has no own property of this name.

Returns ​

T

The property value, or the default value.

Inherited from ​

Provider.getProperty


getPrototypeOf() ​

static getPrototypeOf(o): any

Returns the prototype of an object.

Parameters ​

o ​

any

The object that references the prototype.

Returns ​

any

Inherited from ​

Provider.getPrototypeOf


getRepository() ​

getRepository<Entity>(target): Repository<Entity>

The repository of an entity, created once per entity: its find, save, delete… operations outside a transaction (in a transaction, use the entity manager given to the callback).

Type Parameters ​

Entity ​

Entity extends ObjectLiteral

Parameters ​

target ​

EntityTarget<Entity>

The entity class, its name, or its EntitySchema.

Returns ​

Repository<Entity>

The repository of the entity (a MongoRepository on a MongoDB connection).

Throws ​

From the repository operations, when the entity is not registered.


getTreeRepository() ​

getTreeRepository<Entity>(target): TreeRepository<Entity>

The tree repository of an entity decorated with @Tree(): the operations on its ancestors and descendants (findTrees, findDescendants…).

Type Parameters ​

Entity ​

Entity extends ObjectLiteral

Parameters ​

target ​

EntityTarget<Entity>

The tree entity class, or its name.

Returns ​

TreeRepository<Entity>

The tree repository of the entity.

Throws ​

On a driver without tree support (MongoDB).


hasMetadata() ​

hasMetadata(target): boolean

Whether an entity is registered on the connection.

Parameters ​

target ​

EntityTarget<any>

The entity class, its name, or its table name.

Returns ​

boolean

true when the connection has its metadata.


hasMethod() ​

hasMethod(name): boolean

Whether the object has a method of this name or symbol (a function of its class, not an own property).

Parameters ​

name ​

string | symbol

The method name or symbol.

Returns ​

boolean

true when the method exists.

Inherited from ​

Provider.hasMethod


hasOwn() ​

static hasOwn(o, v): boolean

Determines whether an object has a property with the specified name.

Parameters ​

o ​

object

An object.

v ​

PropertyKey

A property name.

Returns ​

boolean

Inherited from ​

Provider.hasOwn


hasOwnProperty() ​

hasOwnProperty(v): boolean

Determines whether an object has a property with the specified name.

Parameters ​

v ​

PropertyKey

A property name.

Returns ​

boolean

Inherited from ​

Provider.hasOwnProperty


hasProperty() ​

hasProperty(propertyKey): boolean

Whether the object has an own property (not a method or accessor of its class) of this name or symbol.

Parameters ​

propertyKey ​

string | symbol

The property name or symbol.

Returns ​

boolean

true when the property exists.

Inherited from ​

Provider.hasProperty


is() ​

static is(value1, value2): boolean

Returns true if the values are the same value, false otherwise.

Parameters ​

value1 ​

any

The first value.

value2 ​

any

The second value.

Returns ​

boolean

Inherited from ​

Provider.is


isExtensible() ​

static isExtensible(o): boolean

Returns a value that indicates whether new properties can be added to an object.

Parameters ​

o ​

any

Object to test.

Returns ​

boolean

Inherited from ​

Provider.isExtensible


isFrozen() ​

static isFrozen(o): boolean

Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object.

Parameters ​

o ​

any

Object to test.

Returns ​

boolean

Inherited from ​

Provider.isFrozen


isPrototypeOf() ​

isPrototypeOf(v): boolean

Determines whether an object exists in another object's prototype chain.

Parameters ​

v ​

Object

Another object whose prototype chain is to be checked.

Returns ​

boolean

Inherited from ​

Provider.isPrototypeOf


isSealed() ​

static isSealed(o): boolean

Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object.

Parameters ​

o ​

any

Object to test.

Returns ​

boolean

Inherited from ​

Provider.isSealed


keys() ​

Call Signature ​

static keys(o): string[]

Returns the names of the enumerable string properties and methods of an object.

Parameters ​
o ​

object

Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

Returns ​

string[]

Inherited from ​

Provider.keys

Call Signature ​

static keys(o): string[]

Returns the names of the enumerable string properties and methods of an object.

Parameters ​
o ​

{ }

Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

Returns ​

string[]

Inherited from ​

Provider.keys


preventExtensions() ​

static preventExtensions<T>(o): T

Prevents the addition of new properties to an object.

Type Parameters ​

T ​

T

Parameters ​

o ​

T

Object to make non-extensible.

Returns ​

T

Inherited from ​

Provider.preventExtensions


propertyIsEnumerable() ​

propertyIsEnumerable(v): boolean

Determines whether a specified property is enumerable.

Parameters ​

v ​

PropertyKey

A property name.

Returns ​

boolean

Inherited from ​

Provider.propertyIsEnumerable


propertyNames() ​

propertyNames(): string[]

The names of the object's own properties (not its class's methods and accessors).

Returns ​

string[]

The names.

Inherited from ​

Provider.propertyNames


propertySymbols() ​

propertySymbols(): symbol[]

The symbols of the object's own properties.

Returns ​

symbol[]

The symbols.

Inherited from ​

Provider.propertySymbols


query() ​

query<T>(query, parameters?, queryRunner?): Promise<T>

Run a raw SQL query.

Type Parameters ​

T ​

T = any

Parameters ​

query ​

string

The SQL, its parameters as placeholders: $1, $2… for PostgreSQL, ? for MySQL and SQLite.

parameters? ​

any[]

The values of the placeholders, escaped by the driver.

queryRunner? ​

QueryRunner

The query runner to run it on (a transaction of Database.createQueryRunner), a connection of the pool otherwise.

Returns ​

Promise<T>

The raw result of the driver: the rows of a SELECT (an array of objects).

Throws ​

When the database rejects the query.


runMigrations() ​

runMigrations(options?): Promise<Migration[]>

Run the pending migrations (the migrations of the options not yet recorded in the migrations table), in their timestamp order.

Parameters ​

options? ​

MigrationRunOptions

The transactions of the migrations, and whether they are only recorded (fake).

Returns ​

Promise<Migration[]>

The migrations run, an empty array when none is pending.

Throws ​

When the connection is closed.

Throws ​

The error of a failed migration, once its transaction ('all' or 'each') is rolled back.


seal() ​

static seal<T>(o): T

Prevents the modification of attributes of existing properties, and prevents the addition of new properties.

Type Parameters ​

T ​

T

Parameters ​

o ​

T

Object on which to lock the attributes.

Returns ​

T

Inherited from ​

Provider.seal


setProperty() ​

setProperty(propertyKey, value): void

Set a property of the object; the value is not validated, even for a @Configurable property.

Parameters ​

propertyKey ​

string

The property name.

value ​

any

The value.

Returns ​

void

Inherited from ​

Provider.setProperty


setPrototypeOf() ​

static setPrototypeOf(o, proto): any

Sets the prototype of a specified object o to object proto or null. Returns the object o.

Parameters ​

o ​

any

The object to change its prototype.

proto ​

object | null

The value of the new prototype or null.

Returns ​

any

Inherited from ​

Provider.setPrototypeOf


showMigrations() ​

showMigrations(): Promise<boolean>

Log each migration of the options with whether it was run ([X]) or not ([ ]), through the logger of the connection (shown when its logging includes schema).

Returns ​

Promise<boolean>

Whether a migration is pending.


synchronize() ​

synchronize(dropBeforeSync?): Promise<void>

Create or update the database schema from the registered entities (the tables, columns, indices and foreign keys). Meant for development: the migrations change the schema of a production database.

Parameters ​

dropBeforeSync? ​

boolean

Drop every table of the database schema, with its data (also the tables of no entity), before creating the schema. Defaults to false.

Returns ​

Promise<void>

Resolves once the schema is built.

Throws ​

When the connection is closed.


toLocaleString() ​

toLocaleString(): string

Returns a date converted to a string using the current locale.

Returns ​

string

Inherited from ​

Provider.toLocaleString


toString() ​

toString(): string

Returns a string representation of an object.

Returns ​

string

Inherited from ​

Provider.toString


transaction() ​

Call Signature ​

transaction<T>(runInTransaction): Promise<T>

Run a function in a transaction, on one connection of the pool: committed when the function resolves, rolled back when it rejects (its error rethrown). Every operation of the transaction goes through the entity manager given to the function: the ones made through Database.manager or the repositories of this object run outside of it.

Type Parameters ​
T ​

T

Parameters ​
runInTransaction ​

(entityManager) => Promise<T>

The function, given the entity manager of the transaction.

Returns ​

Promise<T>

What the function resolves.

Throws ​

The error of the function, or of the database, after the rollback.

Call Signature ​

transaction<T>(isolationLevel, runInTransaction): Promise<T>

Run a function in a transaction with an isolation level, on one connection of the pool: committed when the function resolves, rolled back when it rejects (its error rethrown). Every operation of the transaction goes through the entity manager given to the function.

Type Parameters ​
T ​

T

Parameters ​
isolationLevel ​

"READ COMMITTED" | "READ UNCOMMITTED" | "REPEATABLE READ" | "SERIALIZABLE" | "SNAPSHOT"

The isolation level: 'READ UNCOMMITTED', 'READ COMMITTED', 'REPEATABLE READ' or 'SERIALIZABLE' (the levels the driver supports).

runInTransaction ​

(entityManager) => Promise<T>

The function, given the entity manager of the transaction.

Returns ​

Promise<T>

What the function resolves.

Throws ​

The error of the function, or of the database, after the rollback.


undoLastMigration() ​

undoLastMigration(options?): Promise<void>

Revert the last migration run (its down()), and remove it from the migrations table. Does nothing when no migration was run.

Parameters ​

options? ​

MigrationRunOptions

The transaction of the migration ('all' by default, migrationsTransactionMode not applying), and whether it is only removed from the migrations table (fake).

Returns ​

Promise<void>

Resolves once the migration is reverted.

Throws ​

When the connection is closed.


valueOf() ​

valueOf(): Object

Returns the primitive value of the specified object.

Returns ​

Object

Inherited from ​

Provider.valueOf


values() ​

Call Signature ​

static values<T>(o): T[]

Returns an array of values of the enumerable own properties of an object

Type Parameters ​
T ​

T

Parameters ​
o ​

{[s: string]: T; } | ArrayLike<T>

Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

Returns ​

T[]

Inherited from ​

Provider.values

Call Signature ​

static values(o): any[]

Returns an array of values of the enumerable own properties of an object

Parameters ​
o ​

{ }

Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

Returns ​

any[]

Inherited from ​

Provider.values

Released under the MIT License.