@zola_do/typeorm 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @zola_do/typeorm
|
|
2
|
+
|
|
3
|
+
TypeORM configuration helpers and service for NestJS applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install individually
|
|
9
|
+
npm install @zola_do/typeorm
|
|
10
|
+
|
|
11
|
+
# Or via meta package
|
|
12
|
+
npm install @zola_do/nestjs-shared
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Configuring the Database
|
|
18
|
+
|
|
19
|
+
Use `TypeOrmConfigHelper` or `dataSourceOptions` to configure TypeORM in your `AppModule`:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Module } from '@nestjs/common';
|
|
23
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
24
|
+
import { dataSourceOptions } from '@zola_do/typeorm';
|
|
25
|
+
|
|
26
|
+
@Module({
|
|
27
|
+
imports: [
|
|
28
|
+
TypeOrmModule.forRoot(dataSourceOptions),
|
|
29
|
+
// ... other modules
|
|
30
|
+
],
|
|
31
|
+
})
|
|
32
|
+
export class AppModule {}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### TypeOrmConfigHelper
|
|
36
|
+
|
|
37
|
+
Access individual config values:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { TypeOrmConfigHelper } from '@zola_do/typeorm';
|
|
41
|
+
|
|
42
|
+
const host = TypeOrmConfigHelper.DATABASE_HOST;
|
|
43
|
+
const port = TypeOrmConfigHelper.DATABASE_PORT;
|
|
44
|
+
const database = TypeOrmConfigHelper.DATABASE_NAME;
|
|
45
|
+
const username = TypeOrmConfigHelper.DATABASE_USER;
|
|
46
|
+
const password = TypeOrmConfigHelper.DATABASE_PASSWORD;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### TypeOrmService
|
|
50
|
+
|
|
51
|
+
Inject the TypeORM service for direct database access when needed:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { TypeOrmService } from '@zola_do/typeorm';
|
|
55
|
+
|
|
56
|
+
@Injectable()
|
|
57
|
+
export class SomeService {
|
|
58
|
+
constructor(private readonly typeorm: TypeOrmService) {}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Environment Variables
|
|
63
|
+
|
|
64
|
+
| Variable | Description | Default |
|
|
65
|
+
|----------|-------------|---------|
|
|
66
|
+
| `DATABASE_HOST` | Database host | `localhost` |
|
|
67
|
+
| `DATABASE_PORT` | Database port | `5432` |
|
|
68
|
+
| `DATABASE_NAME` | Database name | Falls back to `APP_NAME` |
|
|
69
|
+
| `DATABASE_USER` | Database user | `postgres` |
|
|
70
|
+
| `DATABASE_PASSWORD` | Database password | Required in production |
|
|
71
|
+
| `APP_NAME` | Fallback for `DATABASE_NAME` when `DATABASE_NAME` is not set | — |
|
|
72
|
+
|
|
73
|
+
**Note:** In production, `DATABASE_PASSWORD` is required. Either `DATABASE_NAME` or `APP_NAME` must be set.
|
|
74
|
+
|
|
75
|
+
## Related Packages
|
|
76
|
+
|
|
77
|
+
- [@zola_do/core](../core) — Entity base classes
|
|
78
|
+
- [@zola_do/crud](../crud) — Generic CRUD using TypeORM repositories
|
|
79
|
+
- [@zola_do/collection-query](../collection-query) — Query building for TypeORM
|