@zola_do/typeorm
v0.1.10
Published
TypeORM configuration for NestJS
Readme
@zola_do/typeorm
TypeORM configuration helpers and service for NestJS applications.
Installation
# Install individually
npm install @zola_do/typeorm
# Or via meta package
npm install @zola_do/nestjs-sharedUsage
Configuring the Database
Use TypeOrmConfigHelper or dataSourceOptions to configure TypeORM in your AppModule:
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { dataSourceOptions } from '@zola_do/typeorm';
@Module({
imports: [
TypeOrmModule.forRoot(dataSourceOptions),
// ... other modules
],
})
export class AppModule {}TypeOrmConfigHelper
Access individual config values:
import { TypeOrmConfigHelper } from '@zola_do/typeorm';
const host = TypeOrmConfigHelper.DATABASE_HOST;
const port = TypeOrmConfigHelper.DATABASE_PORT;
const database = TypeOrmConfigHelper.DATABASE_NAME;
const username = TypeOrmConfigHelper.DATABASE_USER;
const password = TypeOrmConfigHelper.DATABASE_PASSWORD;TypeOrmService
Inject the TypeORM service for direct database access when needed:
import { TypeOrmService } from '@zola_do/typeorm';
@Injectable()
export class SomeService {
constructor(private readonly typeorm: TypeOrmService) {}
}Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| DATABASE_HOST | Database host | localhost |
| DATABASE_PORT | Database port | 5432 |
| DATABASE_NAME | Database name | Falls back to APP_NAME |
| DATABASE_USER | Database user | postgres |
| DATABASE_PASSWORD | Database password | Required in production |
| APP_NAME | Fallback for DATABASE_NAME when DATABASE_NAME is not set | — |
Note: In production, DATABASE_PASSWORD is required. Either DATABASE_NAME or APP_NAME must be set.
Related Packages
- @zola_do/core — Entity base classes
- @zola_do/crud — Generic CRUD using TypeORM repositories
- @zola_do/collection-query — Query building for TypeORM
