9.0.0 • Published 12 months ago

mieljs-core v9.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

Description 📝

This library wraps the TypeORM module to grant access to "platform" database and his entities just by importing this module.

How to use 🚀

Install this library with

yarn add @ecopass/platform-data

Import the module in the root module of your application indicating the environment. This way the database connection is stablished:

Connect to production database

import { PlatformDataModule } from '@ecopass/platform-data'
/* ... */

@Module({
  imports: [
    PlatformDataModule.forRoot({
      host: process.env.ORM_HOST,
      port: Number(process.env.ORM_PORT),
      username: process.env.ORM_USERNAME,
      password: process.env.ORM_PASSWORD,
      database: process.env.ORM_DATABASE,
      synchronize: JSON.parse(process.env.ORM_SYNC),
      logging: JSON.parse(process.env.ORM_LOGGING),
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Using the entity repository ✅

To use the entities in a custom module and have access to the entities and repositories, you have to import the module with the method forFeature().

/* ... */

@Module({
  imports: [
    PlatformDataModule.forFeature()
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class CustomModule {}

And now you can inject the repositories in your service like this:

import { EventsEntity, UsePlatformRepository } from '@ecopass/platform-data';

@Injectable()
export class CustomService {
  constructor(
    @UsePlatformRepository(EventsEntity)
    private eventRepository: Repository<EventsEntity>
  ) {}

  /* ... */
}
9.0.0

12 months ago