mieljs-core
v9.0.0
Published
Library generates the structures required for initialize a Honeycomb Architecture in NestJS
Downloads
1
Readme
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>
) {}
/* ... */
}