@slickteam/nestjs-pg-typeorm 1.2.5 → 2.0.0

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 CHANGED
@@ -1,70 +1,198 @@
1
- # Slick Nestjs Postresql Typeorm
1
+ # @slickteam/nestjs-pg-typeorm
2
2
 
3
- Available on npmjs.org : [@slickteam/nestjs-pg-typeorm](https://www.npmjs.com/package/@slickteam/nestjs-pg-typeorm)
3
+ [![npm version](https://img.shields.io/npm/v/@slickteam/nestjs-pg-typeorm.svg)](https://www.npmjs.com/package/@slickteam/nestjs-pg-typeorm)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
5
 
5
- ## Usage
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
- - Install dependency
27
+ ```bash
28
+ npm install @slickteam/nestjs-pg-typeorm
29
+ ```
30
+
31
+ Or with pnpm:
8
32
 
9
33
  ```bash
10
- npm i -S @slickteam/nestjs-pg-typeorm
34
+ pnpm add @slickteam/nestjs-pg-typeorm
11
35
  ```
12
36
 
13
- - In your environment file, add these lines :
37
+ ## Configuration
14
38
 
15
- ```conf
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
- # Optionnel
23
- POSTGRESQL_SYNCHRONIZE=false
24
- POSTGRESQL_LOGGER=
25
- POSTGRESQL_ENTITY_PATH=dist/**/*.entity.js,dist/**/*Entity.js,dist/**/**/*.entity.js,dist/**/**/*Entity.js
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
- - In module where you want use this module, add this :
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: [Warp10Module],
35
- controllers: [],
36
- providers: [],
37
- exports: [],
83
+ imports: [DatabaseModule],
38
84
  })
39
- class ExempleModule {}
85
+ export class AppModule {}
40
86
  ```
41
87
 
42
- ## Commands for package.json
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:drop": "typeorm-ts-node-commonjs schema:drop -d ./node_modules/@slickteam/nestjs-pg-typeorm/dist/database-config.js",
48
- "migration:show": "typeorm-ts-node-commonjs migration:show -d ./node_modules/@slickteam/nestjs-pg-typeorm/dist/database-config.js",
49
- "migration:create": "typeorm-ts-node-commonjs migration:create",
50
- "migration:run": "typeorm-ts-node-commonjs migration:run -d ./node_modules/@slickteam/nestjs-pg-typeorm/dist/database-config.js",
51
- "migration:revert": "typeorm-ts-node-commonjs migration:revert -d ./node_modules/@slickteam/nestjs-pg-typeorm/dist/database-config.js"
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
- ## Dependencies version
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
- Nestjs
180
+ ### Help
59
181
 
60
- - `@nestjs/common`: `^11.0.10`
61
- - `@nestjs/config`: `^4.0.0`
182
+ ```bash
183
+ npx slick-migration --help
184
+ ```
62
185
 
63
- Pg
186
+ ## Dependencies
64
187
 
65
- - `pg`: `^8.13.3`
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
- Typeorm
196
+ ## License
68
197
 
69
- - `@nestjs/typeorm`: `^11.0.0`
70
- - `typeorm`: `^0.3.20`
198
+ [MIT](LICENSE) - Slickteam
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
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
@@ -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"}