4.0.0-alpha.42 • Published 3 months ago

@concepta/nestjs-typeorm-ext v4.0.0-alpha.42

Weekly downloads
-
License
BSD-3-Clause
Repository
-
Last release
3 months ago

Rockets NestJS TypeOrm Extended

Extremely powerful extension of the NestJS TypeOrm module that allows your dynamic modules to accept drop-in replacements of custom entities and repositories at registration time.

Project

NPM Latest NPM Downloads GH Last Commit GH Contrib NestJS Dep

Overview

The TypeOrm Ext module provides a powerful wrapper around the @nestjs/typeorm module.

While still using the identical configuration options of the TypeOrm module, you can increase the extensibility of your custom module by designing it to accept custom entity and repository overrides.

This pattern allows you to publish modules that are loosely coupled to their own entity and repository definitions. This enables implementations of your module to define their own concrete data storage.

Installation

yarn add @concepta/nestjs-typeorm-ext

Module Design

Designing your module to use this extension is fairly straight forward, but a bit too verbose for this readme.

To see how this was implemented in our UserModule please refer to that module's user.module.ts

Usage

app.module.ts

// ...
import { TypeOrmExtModule } from '@concepta/nestjs-typeorm-ext';
import { UserModule } from '@concepta/nestjs-user';
import { CustomUserRepository } from 'path/to/custom-user.repository';
import { CustomUser } from 'path/to/custom-user.entity';

@Module({
  imports: [
    TypeOrmExtModule.forRoot({
      type: 'postgres',
      url: 'postgres://user:pass@localhost:5432/postgres',
      entities: [CustomUser],
    }),
    UserModule.forRoot({
      entities: {
        user: { entity: CustomUser, repository: CustomUserRepository },
      },
    }),
  ],
})
export class AppModule {}

Configuration

Data Source Options

The module options are identical the the NestJS TypeOrm module.