0.1.0-beta.6 • Published 4 months ago

@klerick/json-api-nestjs-microorm v0.1.0-beta.6

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

json-api-nestjs-microorm

MocroOrm adapter for json-api-nestjs

Installation

$ npm install @klerick/json-api-nestjs-microorm

Configuration params

The following interface is using for the configuration:

export type MicroOrmParam = {
  arrayType?: string[]; //Custom type for indicate of array
};

NOTE: MikroORM Default Named Context Issue in NestJS

@mikro-orm/nestjs does not create a default named context.

As a result, the module initialization behaves differently depending on whether a single or multiple connections are used. More specifically, the dependency injection token for MikroORM differs between one and multiple database connections.

To maintain a consistent JSON:API module configuration across different database adapters, I decided not to add extra conditional checks in the setup.

For everything to work correctly, @mikro-orm/nestjs should be integrated using the following module: šŸ‘‰ MicroORM Database Module.

import ormConfig from './config';

// need set contextName and registerRequestContext
export const config: Options = {
  contextName: 'default',
  registerRequestContext: false,
  ...ormConfig,
};

@Module({
  imports: [MikroOrmModule.forRoot(config), MikroOrmModule.forMiddleware()],
  exports: [MikroOrmCoreModule],
})
export class MicroOrmDatabaseModule {}