xTaskjs 1.0 is live: role-based accounts, documentation, and a customizable interface.

Packages

@xtaskjs/typeorm

TypeORM integration, datasource registration, and repository injection helpers.

npm install @xtaskjs/typeorm typeorm reflect-metadata Package path: packages/typeorm

Overview

What this package owns in the runtime

TypeORM support attaches datasource lifecycle to xtask startup and shutdown. It gives the container a standard way to inject datasources and repositories while re-exporting the TypeORM surface.

What it provides

  • Registers datasources during bootstrap and destroys them during app.close().
  • Re-exports TypeORM decorators and APIs from one package entry point.
  • Supports datasource decorators and injection helpers.
  • Fits both SQLite demos and larger multi-datasource applications.

How it fits

  • Activated automatically when the package exports initializeTypeOrmIntegration().
  • Used with Fastify in the SQLite sample and with Postgres in this website project.

Usage Chart

How strongly this package shapes the runtime

Bootstrap

4/5

Dependency Injection

4/5

Persistence

5/5

Integrations

5/5

Security

2/5

Package Flow

How this package moves through xtaskjs runtime phases

Before startup

Register datasources with registerTypeOrmDataSource() or TypeOrmDataSource() so xtaskjs knows what to initialize.

During CreateApplication()

The integration opens datasources, publishes repository and datasource tokens into the container, and makes them injectable to services and controllers.

During app.close()

Datasource connections are destroyed automatically so database shutdown is aligned with the main application lifecycle.

API Surface

Representative exports from the upstream package

TypeORM bridge

  • registerTypeOrmDataSource
  • TypeOrmDataSource
  • InjectDataSource
  • InjectRepository
  • TypeOrmMigration
  • TypeOrmSeeder

Re-exported ORM APIs

  • DataSource
  • Entity
  • Column
  • PrimaryGeneratedColumn
  • OneToMany
  • ManyToOne
  • Repository

Lifecycle surface

  • initializeTypeOrmIntegration
  • shutdownTypeOrmIntegration

Usage

Typical adoption flow

1. Register datasource definitions

Describe your datasource once and keep entities, migrations, and connection details close to the app entry point.

2. Inject repositories or datasources

Use the xtask TypeORM decorators and tokens to inject repositories into DI-managed services instead of constructing them manually.

3. Let lifecycle manage connections

Rely on bootstrap and shutdown hooks instead of manual initialize() and destroy() calls across the codebase.

Example

Reference snippet

Datasource registration
import { TypeOrmDataSource } from "@xtaskjs/typeorm";
import { UserEntity } from "./user.entity";

@TypeOrmDataSource({
  name: "default",
  type: "sqlite",
  database: process.env.DB_PATH || "xtask-typeorm.sqlite",
  entities: [UserEntity],
  synchronize: true,
})
export class DatabaseConfig {}

Samples

Official samples to inspect next

Reference samples: 04-typeorm_app