Options
All
  • Public
  • Public/Protected
  • All
Menu

Connection is a single database ORM connection to a specific database. Its not required to be a database connection, depend on database type it can create connection pool. You can have multiple connections to multiple databases in your application.

Hierarchy

  • Connection

Index

Constructors

constructor

Properties

driver

driver: Driver

Database driver used by this connection.

entityMetadatas

entityMetadatas: EntityMetadata[] = []

All entity metadatas that are registered for this connection.

isConnected

isConnected: false = false

Indicates if connection is initialized or not.

logger

logger: Logger

Logger used to log orm events.

manager

manager: EntityManager

EntityManager of this connection.

migrations

migrations: MigrationInterface[] = []

Migration instances that are registered for this connection.

name

name: string

Connection name.

namingStrategy

namingStrategy: NamingStrategyInterface

Naming strategy used in the connection.

options

Connection options.

Optional queryResultCache

queryResultCache: QueryResultCache

Used to work with query result cache.

relationIdLoader

relationIdLoader: RelationIdLoader

Used to load relation ids of specific entity relations.

relationLoader

relationLoader: RelationLoader

Used to load relations and work with lazy relations.

subscribers

subscribers: EntitySubscriberInterface<any>[] = []

Entity subscriber instances that are registered for this connection.

Accessors

mongoManager

  • Gets the mongodb entity manager that allows to perform mongodb-specific repository operations with any entity in this connection.

    Available only in mongodb connections.

    Returns MongoEntityManager

sqljsManager

Methods

Protected buildMetadatas

  • buildMetadatas(): void

close

  • close(): Promise<void>
  • Closes connection with the database. Once connection is closed, you cannot use repositories or perform any operations except opening connection again.

    Returns Promise<void>

connect

  • connect(): Promise<this>
  • Performs connection to the database. This method should be called once on application bootstrap. This method not necessarily creates database connection (depend on database type), but it also can setup a connection pool with database to use.

    Returns Promise<this>

createEntityManager

createQueryBuilder

createQueryRunner

  • createQueryRunner(mode?: "master" | "slave"): QueryRunner
  • Creates a query runner used for perform queries on a single database connection. Using query runners you can control your queries to execute using single database connection and manually control your database transaction.

    Mode is used in replication mode and indicates whatever you want to connect to master database or any of slave databases. If you perform writes you must use master database, if you perform reads you can use slave databases.

    Parameters

    • Default value mode: "master" | "slave" = "master"

    Returns QueryRunner

dropDatabase

  • dropDatabase(): Promise<void>
  • Drops the database and all its data. Be careful with this method on production since this method will erase all your database tables and their data. Can be used only after connection to the database is established.

    Returns Promise<void>

Protected findMetadata

getCustomRepository

  • getCustomRepository<T>(customRepository: ObjectType<T>): T

getManyToManyMetadata

  • getManyToManyMetadata(entityTarget: Function | string, relationPropertyPath: string): undefined | EntityMetadata
  • Gets entity metadata of the junction table (many-to-many table).

    Parameters

    • entityTarget: Function | string
    • relationPropertyPath: string

    Returns undefined | EntityMetadata

getMetadata

getMongoRepository

getRepository

getTreeRepository

hasMetadata

  • hasMetadata(target: Function | EntitySchema<any> | string): boolean
  • Checks if entity metadata exist for the given entity class, target name or table name.

    Parameters

    Returns boolean

query

  • query(query: string, parameters?: any[], queryRunner?: QueryRunner): Promise<any>
  • Executes raw SQL query and returns raw database results.

    Parameters

    • query: string
    • Optional parameters: any[]
    • Optional queryRunner: QueryRunner

    Returns Promise<any>

runMigrations

  • runMigrations(options?: undefined | object): Promise<void>
  • Runs all pending migrations. Can be used only after connection to the database is established.

    Parameters

    • Optional options: undefined | object

    Returns Promise<void>

synchronize

  • synchronize(dropBeforeSync?: boolean): Promise<void>
  • Creates database schema for all entities registered in this connection. Can be used only after connection to the database is established.

    Parameters

    • Default value dropBeforeSync: boolean = false

      If set to true then it drops the database with all its tables and data

    Returns Promise<void>

transaction

  • transaction(runInTransaction: function): Promise<any>
  • Wraps given function execution (and all operations made there) into a transaction. All database operations must be executed using provided entity manager.

    Parameters

    • runInTransaction: function

    Returns Promise<any>

undoLastMigration

  • undoLastMigration(options?: undefined | object): Promise<void>
  • Reverts last executed migration. Can be used only after connection to the database is established.

    Parameters

    • Optional options: undefined | object

    Returns Promise<void>

Generated using TypeDoc