DataSource API
options- Options used to create this dataSource. Learn more about Data Source Options.
const dataSourceOptions: DataSourceOptions = dataSource.optionsisInitialized- Indicates if theDataSourcewas initialized and the connection / connection pool with the database was established or not.
const isInitialized: boolean = dataSource.isInitializeddriver- Underlying database driver used in this dataSource.
const driver: Driver = dataSource.drivermanager-EntityManagerused to work with entities. Learn more about Entity Manager and Repository.
const manager: EntityManager = dataSource.manager
// you can call manager methods, for example find:
const users = await manager.find()mongoManager-MongoEntityManagerused to work with entities for mongodb data source. For more information about MongoEntityManager see MongoDB documentation.
const manager: MongoEntityManager = dataSource.mongoManager
// you can call manager or mongodb-manager specific methods, for example find:
const users = await manager.find()initialize- Initializes data source and opens connection pool to the database.
await dataSource.initialize()destroy- Destroys the DataSource and closes all database connections. Usually, you call this method when your application is shutting down.
await dataSource.destroy()synchronize- Synchronizes database schema. Whensynchronize: trueis set in data source options it calls this method. Usually, you call this method when your application is starting.
dropDatabase- 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.
runMigrations- Runs all pending migrations.
undoLastMigration- Reverts last executed migration.
hasMetadata- Checks if metadata for a given entity is registered.
getMetadata- GetsEntityMetadataof the given entity. You can also specify a table name and if entity metadata with such table name is found it will be returned.
getRepository- GetsRepositoryof the given entity. You can also specify a table name and if repository for given table is found it will be returned. Learn more about Repositories.
getTreeRepository- GetsTreeRepositoryof the given entity. You can also specify a table name and if repository for given table is found it will be returned. Learn more about Repositories.
getMongoRepository- GetsMongoRepositoryof the given entity. This repository is used for entities in MongoDB dataSource. Learn more about MongoDB support.
transaction- Provides a single transaction where multiple database requests will be executed in a single database transaction. Learn more about Transactions.
query- Executes a raw SQL query.
sql- Executes a raw SQL query using template literals.
Learn more about using the SQL Tag syntax.
createQueryBuilder- Creates a query builder, which can be used to build queries. Learn more about QueryBuilder.
createQueryRunner- Creates a query runner used to manage and work with a single real database dataSource. Learn more about QueryRunner.
Last updated