API 参考
    正在准备搜索索引...

    DataSource is a pre-defined connection configuration to a specific database. You can have multiple data sources connected (with multiple connections in it), connected to multiple databases in your application.

    Before, it was called Connection, but now Connection is deprecated because Connection isn't the best name for what it's actually is.

    层级 (查看层级一览)

    索引

    构造函数

    • 参数

      返回 DataSource

    属性

    "@instanceof": symbol
    driver: Driver

    Database driver used by this connection.

    entityMetadatas: EntityMetadata[]

    All entity metadatas that are registered for this connection.

    entityMetadatasMap: Map<EntityTarget<any>, EntityMetadata>

    All entity metadatas that are registered for this connection. This is a copy of #.entityMetadatas property -> used for more performant searches.

    isInitialized: boolean

    Indicates if DataSource is initialized or not.

    logger: Logger

    Logger used to log orm events.

    manager: EntityManager

    EntityManager of this connection.

    metadataTableName: string

    Name for the metadata table

    migrations: MigrationInterface[]

    Migration instances that are registered for this connection.

    name: string

    Connection name.

    we don't need names anymore since we are going to drop all related methods relying on this property.

    namingStrategy: NamingStrategyInterface

    Naming strategy used in the connection.

    Connection options.

    queryResultCache?: QueryResultCache

    Used to work with query result cache.

    relationIdLoader: RelationIdLoader
    relationLoader: RelationLoader

    Used to load relations and work with lazy relations.

    subscribers: EntitySubscriberInterface<any>[]

    Entity subscriber instances that are registered for this connection.

    访问器

    • get isConnected(): boolean

      Indicates if DataSource is initialized or not. * *

      返回 boolean

      use .isInitialized instead

    • get mongoManager(): MongoEntityManager

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

      Available only in mongodb connections.

      返回 MongoEntityManager

    • get sqljsManager(): SqljsEntityManager

      Gets a sql.js specific Entity Manager that allows to perform special load and save operations

      Available only in connection with the sqljs driver.

      返回 SqljsEntityManager

    方法

    • Builds metadatas for all registered classes inside this connection.

      返回 Promise<void>

    • Closes connection with the database. Once connection is closed, you cannot use repositories or perform any operations except opening connection again.

      返回 Promise<void>

      use .destroy method instead

    • 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.

      返回 Promise<DataSource>

      use .initialize method instead

    • Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.

      参数

      返回 EntityManager

    • Creates a new query builder that can be used to build a SQL query.

      类型参数

      参数

      返回 SelectQueryBuilder<Entity>

    • Creates a new query builder that can be used to build a SQL query.

      参数

      返回 SelectQueryBuilder<any>

    • 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.

      参数

      返回 QueryRunner

    • Get the replication mode SELECT queries should use for this datasource by default

      返回 ReplicationMode

    • Closes connection with the database. Once connection is closed, you cannot use repositories or perform any operations except opening connection again.

      返回 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.

      返回 Promise<void>

    • Finds exist entity metadata by the given entity class, target name or table name.

      参数

      返回 undefined | EntityMetadata

    • Gets custom entity repository marked with

      类型参数

      • T

      参数

      返回 T

      decorator.

      use Repository.extend function to create a custom repository

    • Gets entity metadata of the junction table (many-to-many table).

      参数

      返回 undefined | EntityMetadata

    • Gets entity metadata for the given entity class or schema name.

      参数

      返回 EntityMetadata

    • Gets tree repository for the given entity class or name. Only tree-type entities can have a TreeRepository, like ones decorated with

      类型参数

      参数

      返回 TreeRepository<Entity>

      decorator.

    • Checks if entity metadata exist for the given entity class, target name or table name.

      参数

      返回 boolean

    • 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.

      返回 Promise<DataSource>

    • Executes raw SQL query and returns raw database results.

      类型参数

      • T = any

      参数

      • query: string
      • 可选parameters: any[]
      • 可选queryRunner: QueryRunner

      返回 Promise<T>

      Official docs for examples.

    • Runs all pending migrations. Can be used only after connection to the database is established.

      参数

      • 可选options: { fake?: boolean; transaction?: "all" | "none" | "each" }

      返回 Promise<Migration[]>

    • Updates current connection options with provided options.

      参数

      返回 this

    • Lists all migrations and whether they have been run. Returns true if there are pending migrations

      返回 Promise<boolean>

    • Creates database schema for all entities registered in this connection. Can be used only after connection to the database is established.

      参数

      • 可选dropBeforeSync: boolean

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

      返回 Promise<void>

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

      类型参数

      • T

      参数

      返回 Promise<T>

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

      类型参数

      • T

      参数

      • isolationLevel: IsolationLevel
      • runInTransaction: (entityManager: EntityManager) => Promise<T>

      返回 Promise<T>

    • Reverts last executed migration. Can be used only after connection to the database is established.

      参数

      • 可选options: { fake?: boolean; transaction?: "all" | "none" | "each" }

      返回 Promise<void>