Repository navigation
@142vip.nest typeorm.类.DataSource
API 参考 / @142vip/nest-typeorm / DataSource
定义于: 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:33
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.
new DataSource(
options):DataSource
定义于: 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
DataSource
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
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.
readonlyentityMetadatas: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.
readonlyentityMetadatasMap: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.
readonlyisInitialized: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.
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.
readonlymanager: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.
readonlymetadataTableName: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
readonlymigrations: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.
readonlyname: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.
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.
readonlyoptions: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.
optionalqueryResultCache?: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.
readonlyrelationIdLoader: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
readonlyrelationLoader: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.
readonlysubscribers: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.
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
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.
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
protectedbuildMetadatas():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>
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
connect():
Promise<DataSource>
定义于: 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<DataSource>
use .initialize method instead
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.
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 extends ObjectLiteral
EntityTarget<Entity>
string
SelectQueryBuilder<Entity>
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.
SelectQueryBuilder<any>
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.
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
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>
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>
protectedfindMetadata(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.
EntityTarget<any>
EntityMetadata | undefined
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
ObjectType<T>
T
decorator.
use Repository.extend function to create a custom repository
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<any>
string
EntityMetadata | undefined
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.
EntityTarget<any>
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 extends ObjectLiteral
EntityTarget<Entity>
MongoRepository<Entity>
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 extends ObjectLiteral
EntityTarget<Entity>
Repository<Entity>
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 extends ObjectLiteral
EntityTarget<Entity>
TreeRepository<Entity>
decorator.
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.
EntityTarget<any>
boolean
initialize():
Promise<DataSource>
定义于: 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<DataSource>
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 = any
string
any[]
Promise<T>
Official docs for examples.
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.
boolean
"all" | "none" | "each"
Promise<Migration[]>
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.
Partial<DataSourceOptions>
this
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>
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 = any
TemplateStringsArray
...unknown[]
Promise<T>
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.
boolean
If set to true then it drops the database with all its tables and data
Promise<void>
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
(entityManager) => Promise<T>
Promise<T>
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
IsolationLevel
(entityManager) => Promise<T>
Promise<T>
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.
boolean
"all" | "none" | "each"
Promise<void>
- @142vip/axios
- @142vip/changelog
- @142vip/commit-linter
- @142vip/copyright
- @142vip/data-source
- @142vip/eslint-config
- @142vip/fairy-cli
- @142vip/grpc
- @142vip/nest
- @142vip/nest-redis
- @142vip/nest-typeorm
- @142vip/oauth2.0
- @142vip/open-source
- @142vip/redis
- @142vip/release-version
- @142vip/typeorm
- @142vip/utils