Skip to content

@142vip.nest typeorm.类.Connection

mmdapl edited this page Oct 8, 2026 · 1 revision

API 参考 / @142vip/nest-typeorm / Connection

类: Connection

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/connection/Connection.d.ts:9

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.

已被弃用

theme_extends

构造函数

构造函数

new Connection(options): Connection

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:95

参数

options

DataSourceOptions

返回

Connection

继承自

DataSource.constructor

属性

@instanceof

readonly @instanceof: symbol

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:34

继承自

DataSource.@instanceof


driver

driver: Driver

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:52

Database driver used by this connection.

继承自

DataSource.driver


entityMetadatas

readonly entityMetadatas: EntityMetadata[]

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:80

All entity metadatas that are registered for this connection.

继承自

DataSource.entityMetadatas


entityMetadatasMap

readonly entityMetadatasMap: Map<EntityTarget<any>, EntityMetadata>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:85

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

继承自

DataSource.entityMetadatasMap


isInitialized

readonly isInitialized: boolean

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:48

Indicates if DataSource is initialized or not.

继承自

DataSource.isInitialized


logger

logger: Logger

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:68

Logger used to log orm events.

继承自

DataSource.logger


manager

readonly manager: EntityManager

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:56

EntityManager of this connection.

继承自

DataSource.manager


metadataTableName

readonly metadataTableName: string

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:64

Name for the metadata table

继承自

DataSource.metadataTableName


migrations

readonly migrations: MigrationInterface[]

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:72

Migration instances that are registered for this connection.

继承自

DataSource.migrations


name

readonly name: string

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:40

Connection name.

已被弃用

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

继承自

DataSource.name


namingStrategy

namingStrategy: NamingStrategyInterface

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:60

Naming strategy used in the connection.

继承自

DataSource.namingStrategy


options

readonly options: DataSourceOptions

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:44

Connection options.

继承自

DataSource.options


queryResultCache?

optional queryResultCache?: QueryResultCache

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:89

Used to work with query result cache.

继承自

DataSource.queryResultCache


relationIdLoader

readonly relationIdLoader: RelationIdLoader

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:94

继承自

DataSource.relationIdLoader


relationLoader

readonly relationLoader: RelationLoader

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:93

Used to load relations and work with lazy relations.

继承自

DataSource.relationLoader


subscribers

readonly subscribers: EntitySubscriberInterface<any>[]

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:76

Entity subscriber instances that are registered for this connection.

继承自

DataSource.subscribers

访问器

isConnected

Getter 签名

get isConnected(): boolean

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:101

Indicates if DataSource is initialized or not. * *

已被弃用

use .isInitialized instead

返回

boolean

继承自

DataSource.isConnected


mongoManager

Getter 签名

get mongoManager(): MongoEntityManager

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:108

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

继承自

DataSource.mongoManager


sqljsManager

Getter 签名

get sqljsManager(): SqljsEntityManager

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:114

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

继承自

DataSource.sqljsManager

方法

buildMetadatas()

protected buildMetadatas(): Promise<void>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:263

Builds metadatas for all registered classes inside this connection.

返回

Promise<void>

继承自

DataSource.buildMetadatas


close()

close(): Promise<void>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:146

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

继承自

DataSource.close


connect()

connect(): Promise<Connection>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:134

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<Connection>

已被弃用

use .initialize method instead

继承自

DataSource.connect


createEntityManager()

createEntityManager(queryRunner?): EntityManager

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:255

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

参数

queryRunner?

QueryRunner

返回

EntityManager

继承自

DataSource.createEntityManager


createQueryBuilder()

调用签名

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

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:232

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

类型参数
Entity

Entity extends ObjectLiteral

参数
entityClass

EntityTarget<Entity>

alias

string

queryRunner?

QueryRunner

返回

SelectQueryBuilder<Entity>

继承自

DataSource.createQueryBuilder

调用签名

createQueryBuilder(queryRunner?): SelectQueryBuilder<any>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:236

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

参数
queryRunner?

QueryRunner

返回

SelectQueryBuilder<any>

继承自

DataSource.createQueryBuilder


createQueryRunner()

createQueryRunner(mode?): QueryRunner

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:247

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.

参数

mode?

ReplicationMode

返回

QueryRunner

继承自

DataSource.createQueryRunner


defaultReplicationModeForReads()

defaultReplicationModeForReads(): ReplicationMode

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:267

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

返回

ReplicationMode

继承自

DataSource.defaultReplicationModeForReads


destroy()

destroy(): Promise<void>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:139

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

返回

Promise<void>

继承自

DataSource.destroy


dropDatabase()

dropDatabase(): Promise<void>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:159

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>

继承自

DataSource.dropDatabase


findMetadata()

protected findMetadata(target): EntityMetadata | undefined

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:259

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

参数

target

EntityTarget<any>

返回

EntityMetadata | undefined

继承自

DataSource.findMetadata


getCustomRepository()

getCustomRepository<T>(customRepository): T

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:208

Gets custom entity repository marked with

类型参数

T

T

参数

customRepository

ObjectType<T>

返回

T

Entity Repository

decorator.

已被弃用

use Repository.extend function to create a custom repository

继承自

DataSource.getCustomRepository


getManyToManyMetadata()

getManyToManyMetadata(entityTarget, relationPropertyPath): EntityMetadata | undefined

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:251

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

参数

entityTarget

EntityTarget<any>

relationPropertyPath

string

返回

EntityMetadata | undefined

继承自

DataSource.getManyToManyMetadata


getMetadata()

getMetadata(target): EntityMetadata

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:188

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

参数

target

EntityTarget<any>

返回

EntityMetadata

继承自

DataSource.getMetadata


getMongoRepository()

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

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:202

Gets mongodb-specific repository for the given entity class or name. Works only if connection is mongodb-specific.

类型参数

Entity

Entity extends ObjectLiteral

参数

target

EntityTarget<Entity>

返回

MongoRepository<Entity>

继承自

DataSource.getMongoRepository


getRepository()

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

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:192

Gets repository for the given entity.

类型参数

Entity

Entity extends ObjectLiteral

参数

target

EntityTarget<Entity>

返回

Repository<Entity>

继承自

DataSource.getRepository


getTreeRepository()

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

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:197

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

类型参数

Entity

Entity extends ObjectLiteral

参数

target

EntityTarget<Entity>

返回

TreeRepository<Entity>

Tree

decorator.

继承自

DataSource.getTreeRepository


hasMetadata()

hasMetadata(target): boolean

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:184

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

参数

target

EntityTarget<any>

返回

boolean

继承自

DataSource.hasMetadata


initialize()

initialize(): Promise<Connection>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:125

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<Connection>

继承自

DataSource.initialize


query()

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

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:220

Executes raw SQL query and returns raw database results.

类型参数

T

T = any

参数

query

string

parameters?

any[]

queryRunner?

QueryRunner

返回

Promise<T>

参阅

Official docs for examples.

继承自

DataSource.query


runMigrations()

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

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:164

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

参数

options?
fake?

boolean

transaction?

"all" | "none" | "each"

返回

Promise<Migration[]>

继承自

DataSource.runMigrations


setOptions()

setOptions(options): this

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:118

Updates current connection options with provided options.

参数

options

Partial<DataSourceOptions>

返回

this

继承自

DataSource.setOptions


showMigrations()

showMigrations(): Promise<boolean>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:180

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

返回

Promise<boolean>

继承自

DataSource.showMigrations


sql()

sql<T>(strings, ...values): Promise<T>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:228

Tagged template function that executes raw SQL query and returns raw database results. Template expressions are automatically transformed into database parameters. Raw query execution is supported only by relational databases (MongoDB is not supported). Note: Don't call this as a regular function, it is meant to be used with backticks to tag a template literal. Example: dataSource.sqlSELECT * FROM table_name WHERE id = ${id}

类型参数

T

T = any

参数

strings

TemplateStringsArray

values

...unknown[]

返回

Promise<T>

继承自

DataSource.sql


synchronize()

synchronize(dropBeforeSync?): Promise<void>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:153

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>

继承自

DataSource.synchronize


transaction()

调用签名

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

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:213

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

类型参数
T

T

参数
runInTransaction

(entityManager) => Promise<T>

返回

Promise<T>

继承自

DataSource.transaction

调用签名

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

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:214

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

类型参数
T

T

参数
isolationLevel

IsolationLevel

runInTransaction

(entityManager) => Promise<T>

返回

Promise<T>

继承自

DataSource.transaction


undoLastMigration()

undoLastMigration(options?): Promise<void>

定义于: node_modules/.pnpm/typeorm@0.3.30_ioredis@5.6.0_mongodb@6.19.0_mssql@11.0.1_mysql2@3.15.1_pg@8.11.3_ts-node@10.9_6zvdq3z7xgsf663jy3j6oymho4/node_modules/typeorm/data-source/DataSource.d.ts:172

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

参数

options?
fake?

boolean

transaction?

"all" | "none" | "each"

返回

Promise<void>

继承自

DataSource.undoLastMigration

Clone this wiki locally