@slickteam/nestjs-pg-typeorm 1.3.0 → 2.0.1
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 +162 -34
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +55 -0
- package/dist/cli.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +18 -15
package/README.md
CHANGED
|
@@ -1,70 +1,198 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @slickteam/nestjs-pg-typeorm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@slickteam/nestjs-pg-typeorm)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
A NestJS module that provides pre-configured PostgreSQL database integration using TypeORM.
|
|
7
|
+
|
|
8
|
+
## Table of Contents
|
|
9
|
+
|
|
10
|
+
- [Prerequisites](#prerequisites)
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Configuration](#configuration)
|
|
13
|
+
- [Usage](#usage)
|
|
14
|
+
- [Exports](#exports)
|
|
15
|
+
- [Migration Commands](#migration-commands)
|
|
16
|
+
- [Dependencies](#dependencies)
|
|
17
|
+
- [License](#license)
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
- Node.js >= 18
|
|
22
|
+
- NestJS >= 11
|
|
23
|
+
- PostgreSQL database
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
6
26
|
|
|
7
|
-
|
|
27
|
+
```bash
|
|
28
|
+
npm install @slickteam/nestjs-pg-typeorm
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or with pnpm:
|
|
8
32
|
|
|
9
33
|
```bash
|
|
10
|
-
|
|
34
|
+
pnpm add @slickteam/nestjs-pg-typeorm
|
|
11
35
|
```
|
|
12
36
|
|
|
13
|
-
|
|
37
|
+
## Configuration
|
|
14
38
|
|
|
15
|
-
|
|
39
|
+
Add the following environment variables to your `.env` file:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Required
|
|
16
43
|
POSTGRESQL_ADDON_HOST=localhost
|
|
17
44
|
POSTGRESQL_ADDON_PORT=5432
|
|
18
45
|
POSTGRESQL_ADDON_USER=user
|
|
19
46
|
POSTGRESQL_ADDON_PASSWORD=password
|
|
20
47
|
POSTGRESQL_ADDON_DB=db_name
|
|
21
48
|
POSTGRESQL_MAX_POOL_SIZE=25
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
|
|
50
|
+
# Optional
|
|
51
|
+
POSTGRESQL_SYNCHRONIZE=false # Auto-sync schema (disable in production)
|
|
52
|
+
POSTGRESQL_LOGGER= # Logger type: advanced-console | simple-console | file | debug
|
|
53
|
+
POSTGRESQL_LOGGING=false # Enable SQL query logging
|
|
54
|
+
POSTGRESQL_ENTITY_PATH=dist/**/*.entity.js,dist/**/*Entity.js
|
|
26
55
|
POSTGRESQL_MIGRATION_PATH=dist/migration/*.js
|
|
27
|
-
POSTGRESQL_LOGGING=
|
|
28
56
|
```
|
|
29
57
|
|
|
30
|
-
|
|
58
|
+
### Environment Variables Reference
|
|
59
|
+
|
|
60
|
+
| Variable | Required | Default | Description |
|
|
61
|
+
| --------------------------- | -------- | --------------------------------------- | -------------------------------- |
|
|
62
|
+
| `POSTGRESQL_ADDON_HOST` | Yes | - | Database host |
|
|
63
|
+
| `POSTGRESQL_ADDON_PORT` | Yes | - | Database port |
|
|
64
|
+
| `POSTGRESQL_ADDON_USER` | Yes | - | Database user |
|
|
65
|
+
| `POSTGRESQL_ADDON_PASSWORD` | Yes | - | Database password |
|
|
66
|
+
| `POSTGRESQL_ADDON_DB` | Yes | - | Database name |
|
|
67
|
+
| `POSTGRESQL_MAX_POOL_SIZE` | Yes | - | Connection pool size |
|
|
68
|
+
| `POSTGRESQL_SYNCHRONIZE` | No | `false` | Auto-synchronize database schema |
|
|
69
|
+
| `POSTGRESQL_LOGGER` | No | - | TypeORM logger type |
|
|
70
|
+
| `POSTGRESQL_LOGGING` | No | `false` | Enable query logging |
|
|
71
|
+
| `POSTGRESQL_ENTITY_PATH` | No | `dist/**/*entity.js,dist/**/*Entity.js` | Glob patterns for entity files |
|
|
72
|
+
| `POSTGRESQL_MIGRATION_PATH` | No | `dist/migration/*.js` | Glob pattern for migration files |
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
Import the `DatabaseModule` in your application module:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { Module } from '@nestjs/common';
|
|
80
|
+
import { DatabaseModule } from '@slickteam/nestjs-pg-typeorm';
|
|
31
81
|
|
|
32
|
-
```ts
|
|
33
82
|
@Module({
|
|
34
|
-
imports: [
|
|
35
|
-
controllers: [],
|
|
36
|
-
providers: [],
|
|
37
|
-
exports: [],
|
|
83
|
+
imports: [DatabaseModule],
|
|
38
84
|
})
|
|
39
|
-
class
|
|
85
|
+
export class AppModule {}
|
|
40
86
|
```
|
|
41
87
|
|
|
42
|
-
|
|
88
|
+
### Using with Entities
|
|
89
|
+
|
|
90
|
+
Register your entities using `TypeOrmModule.forFeature()`:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { Module } from '@nestjs/common';
|
|
94
|
+
import { DatabaseModule, TypeOrmModule } from '@slickteam/nestjs-pg-typeorm';
|
|
95
|
+
|
|
96
|
+
import { User } from './entities/user.entity';
|
|
97
|
+
import { UserService } from './user.service';
|
|
98
|
+
|
|
99
|
+
@Module({
|
|
100
|
+
imports: [DatabaseModule, TypeOrmModule.forFeature([User])],
|
|
101
|
+
providers: [UserService],
|
|
102
|
+
})
|
|
103
|
+
export class UserModule {}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Injecting Repositories
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { Injectable } from '@nestjs/common';
|
|
110
|
+
import { InjectRepository, Repository } from '@slickteam/nestjs-pg-typeorm';
|
|
111
|
+
|
|
112
|
+
import { User } from './entities/user.entity';
|
|
113
|
+
|
|
114
|
+
@Injectable()
|
|
115
|
+
export class UserService {
|
|
116
|
+
constructor(
|
|
117
|
+
@InjectRepository(User)
|
|
118
|
+
private readonly userRepository: Repository<User>,
|
|
119
|
+
) {}
|
|
120
|
+
|
|
121
|
+
findAll(): Promise<User[]> {
|
|
122
|
+
return this.userRepository.find();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Exports
|
|
128
|
+
|
|
129
|
+
This module re-exports all TypeORM exports and provides the following:
|
|
130
|
+
|
|
131
|
+
| Export | Description |
|
|
132
|
+
| --------------------------- | ---------------------------------------- |
|
|
133
|
+
| `DatabaseModule` | Pre-configured TypeORM module |
|
|
134
|
+
| `TypeOrmModule` | NestJS TypeORM module for entity binding |
|
|
135
|
+
| `TypeOrmModuleAsyncOptions` | Async configuration options type |
|
|
136
|
+
| `TypeOrmModuleOptions` | Configuration options type |
|
|
137
|
+
| `TypeOrmOptionsFactory` | Options factory interface |
|
|
138
|
+
| `InjectDataSource` | Decorator to inject DataSource |
|
|
139
|
+
| `InjectEntityManager` | Decorator to inject EntityManager |
|
|
140
|
+
| `InjectRepository` | Decorator to inject Repository |
|
|
141
|
+
|
|
142
|
+
All TypeORM exports (Entity, Column, Repository, etc.) are also available directly from this package.
|
|
143
|
+
|
|
144
|
+
## Migration Commands
|
|
145
|
+
|
|
146
|
+
This package provides the `slick-migration` CLI for managing database migrations.
|
|
147
|
+
|
|
148
|
+
### Using with npx
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npx slick-migration <command> [options]
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Using with package.json scripts
|
|
43
155
|
|
|
44
156
|
```json
|
|
45
157
|
{
|
|
46
158
|
"scripts": {
|
|
47
|
-
"migration:
|
|
48
|
-
"migration:
|
|
49
|
-
"migration:
|
|
50
|
-
"migration:
|
|
51
|
-
"migration:
|
|
159
|
+
"migration:create": "slick-migration create",
|
|
160
|
+
"migration:generate": "slick-migration generate",
|
|
161
|
+
"migration:run": "slick-migration run",
|
|
162
|
+
"migration:revert": "slick-migration revert",
|
|
163
|
+
"migration:show": "slick-migration show",
|
|
164
|
+
"migration:drop": "slick-migration drop"
|
|
52
165
|
}
|
|
53
166
|
}
|
|
54
167
|
```
|
|
55
168
|
|
|
56
|
-
|
|
169
|
+
### Commands Reference
|
|
170
|
+
|
|
171
|
+
| Command | Description | Example |
|
|
172
|
+
| ---------- | ---------------------------------------- | -------------------------------------------------- |
|
|
173
|
+
| `create` | Create a new empty migration file | `slick-migration create src/migrations/CreateUser` |
|
|
174
|
+
| `generate` | Generate a migration from schema changes | `slick-migration generate src/migrations/AddEmail` |
|
|
175
|
+
| `run` | Run pending migrations | `slick-migration run` |
|
|
176
|
+
| `revert` | Revert the last executed migration | `slick-migration revert` |
|
|
177
|
+
| `show` | Show all migrations and their status | `slick-migration show` |
|
|
178
|
+
| `drop` | Drop the database schema | `slick-migration drop` |
|
|
57
179
|
|
|
58
|
-
|
|
180
|
+
### Help
|
|
59
181
|
|
|
60
|
-
|
|
61
|
-
-
|
|
182
|
+
```bash
|
|
183
|
+
npx slick-migration --help
|
|
184
|
+
```
|
|
62
185
|
|
|
63
|
-
|
|
186
|
+
## Dependencies
|
|
64
187
|
|
|
65
|
-
|
|
188
|
+
| Package | Version |
|
|
189
|
+
| ----------------- | -------- |
|
|
190
|
+
| `@nestjs/common` | ^11.1.12 |
|
|
191
|
+
| `@nestjs/config` | ^4.0.2 |
|
|
192
|
+
| `@nestjs/typeorm` | ^11.0.0 |
|
|
193
|
+
| `typeorm` | 0.3.28 |
|
|
194
|
+
| `pg` | ^8.18.0 |
|
|
66
195
|
|
|
67
|
-
|
|
196
|
+
## License
|
|
68
197
|
|
|
69
|
-
-
|
|
70
|
-
- `typeorm`: `^0.3.20`
|
|
198
|
+
[MIT](LICENSE) - Slickteam
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const command = args[0];
|
|
8
|
+
const restArgs = args.slice(1).join(' ');
|
|
9
|
+
const dataSourcePath = (0, path_1.resolve)(__dirname, 'database-config.js');
|
|
10
|
+
const commands = {
|
|
11
|
+
create: `typeorm-ts-node-commonjs migration:create ${restArgs}`,
|
|
12
|
+
generate: `typeorm-ts-node-commonjs migration:generate -d ${dataSourcePath} ${restArgs}`,
|
|
13
|
+
run: `typeorm-ts-node-commonjs migration:run -d ${dataSourcePath} ${restArgs}`,
|
|
14
|
+
revert: `typeorm-ts-node-commonjs migration:revert -d ${dataSourcePath} ${restArgs}`,
|
|
15
|
+
show: `typeorm-ts-node-commonjs migration:show -d ${dataSourcePath} ${restArgs}`,
|
|
16
|
+
drop: `typeorm-ts-node-commonjs schema:drop -d ${dataSourcePath} ${restArgs}`,
|
|
17
|
+
};
|
|
18
|
+
function printHelp() {
|
|
19
|
+
console.log(`
|
|
20
|
+
slick-migration - TypeORM migration CLI for @slickteam/nestjs-pg-typeorm
|
|
21
|
+
|
|
22
|
+
Usage: slick-migration <command> [options]
|
|
23
|
+
|
|
24
|
+
Commands:
|
|
25
|
+
create <path> Create a new empty migration file
|
|
26
|
+
generate <path> Generate a migration from schema changes
|
|
27
|
+
run Run pending migrations
|
|
28
|
+
revert Revert the last executed migration
|
|
29
|
+
show Show all migrations and their status
|
|
30
|
+
drop Drop the database schema
|
|
31
|
+
|
|
32
|
+
Examples:
|
|
33
|
+
slick-migration create src/migrations/CreateUserTable
|
|
34
|
+
slick-migration generate src/migrations/AddEmailColumn
|
|
35
|
+
slick-migration run
|
|
36
|
+
slick-migration revert
|
|
37
|
+
slick-migration show
|
|
38
|
+
`);
|
|
39
|
+
}
|
|
40
|
+
if (!command || command === '--help' || command === '-h') {
|
|
41
|
+
printHelp();
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
if (!commands[command]) {
|
|
45
|
+
console.error(`Unknown command: ${command}\n`);
|
|
46
|
+
printHelp();
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
(0, child_process_1.execSync)(commands[command], { stdio: 'inherit' });
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,iDAAyC;AACzC,+BAA+B;AAE/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEzC,MAAM,cAAc,GAAG,IAAA,cAAO,EAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAEhE,MAAM,QAAQ,GAA2B;IACvC,MAAM,EAAE,6CAA6C,QAAQ,EAAE;IAC/D,QAAQ,EAAE,kDAAkD,cAAc,IAAI,QAAQ,EAAE;IACxF,GAAG,EAAE,6CAA6C,cAAc,IAAI,QAAQ,EAAE;IAC9E,MAAM,EAAE,gDAAgD,cAAc,IAAI,QAAQ,EAAE;IACpF,IAAI,EAAE,8CAA8C,cAAc,IAAI,QAAQ,EAAE;IAChF,IAAI,EAAE,2CAA2C,cAAc,IAAI,QAAQ,EAAE;CAC9E,CAAC;AAEF,SAAS,SAAS;IAChB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;CAmBb,CAAC,CAAC;AACH,CAAC;AAED,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;IACzD,SAAS,EAAE,CAAC;IACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IACvB,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,IAAI,CAAC,CAAC;IAC/C,SAAS,EAAE,CAAC;IACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,CAAC;IACH,IAAA,wBAAQ,EAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AACpD,CAAC;AAAC,MAAM,CAAC;IACP,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|