@xtaskjs/typeorm
v1.0.10
Published
TypeORM integration for xtaskjs.
Downloads
676
Readme
@xtaskjs/typeorm
TypeORM integration package for xtaskjs.
This package is part of the xtaskjs project, hosted at xtaskjs.io.
Installation
npm install @xtaskjs/typeorm typeorm reflect-metadataWhat It Provides
- Re-exports all TypeORM APIs and decorators (
Entity,Column,OneToMany, etc.). - Datasource lifecycle management integrated with xtask lifecycle.
- Container tokens + decorators for datasource and repository injection.
Configure Datasources
import { registerTypeOrmDataSource } from "@xtaskjs/typeorm";
registerTypeOrmDataSource({
type: "sqlite",
database: "./app.db",
synchronize: true,
entities: [User],
});You can also use the class decorator form:
import { TypeOrmDataSource } from "@xtaskjs/typeorm";
@TypeOrmDataSource({
name: "default",
type: "sqlite",
database: "./app.db",
entities: [User],
synchronize: true,
})
class DatabaseConfig {}Inject Datasource / Repository
import { Service } from "@xtaskjs/core";
import { DataSource, Repository, InjectDataSource, InjectRepository } from "@xtaskjs/typeorm";
@Service({ scope: "singleton" })
export class UserService {
constructor(
@InjectDataSource() private readonly dataSource: DataSource,
@InjectRepository(User) private readonly users: Repository<User>
) {}
}Lifecycle Behavior
- During container registration (
CreateApplicationbootstrap): datasources are initialized. - During
app.close(): initialized datasources are destroyed.
Resources
- Project site and documentation: xtaskjs.io
- npm package: @xtaskjs/typeorm
- Source repository: xtaskjs/xtaskjs
