nest-knexjs 0.0.30 → 0.0.32

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.
Files changed (3) hide show
  1. package/README.md +2 -393
  2. package/_README.md +406 -0
  3. package/package.json +10 -16
package/README.md CHANGED
@@ -1,394 +1,3 @@
1
- <p align="center">
2
- <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="150" alt="Nest Logo" /></a>
3
- </p>
1
+ # nest-knexjs
4
2
 
5
- ## Description
6
-
7
- Knexjs module for Nest framework (node.js)
8
-
9
- ## Installation
10
-
11
- First install the module via `yarn` or `npm` or `pnpm` and do not forget to install the driver package as well:
12
-
13
-
14
- ```bash
15
- $ npm i --save nest-knexjs knex mysql # for mysql/mariadb
16
- $ npm i --save nest-knexjs knex pg # for postgresql
17
- $ npm i --save nest-knexjs knex sqlite # for sqlite
18
- $ npm i --save nest-knexjs knex oracledb # for oracledb
19
- ```
20
- or
21
-
22
- ```bash
23
- $ yarn add nest-knexjs knex mysql # for mysql/mariadb
24
- $ yarn add nest-knexjs knex pg # for postgresql
25
- $ yarn add nest-knexjs knex sqlite # for sqlite
26
- $ yarn add nest-knexjs knex oracledb # for oracledb
27
- ```
28
- or
29
-
30
- ```bash
31
- $ pnpm add nest-knexjs knex mysql # for mysql/mariadb
32
- $ pnpm add nest-knexjs knex pg # for postgresql
33
- $ pnpm add nest-knexjs knex sqlite # for sqlite
34
- $ pnpm add nest-knexjs knex oracledb # for oracledb
35
- ```
36
-
37
- ## Table of Contents
38
-
39
- - [Description](#description)
40
- - [Table of Contents](#table-of-contents)
41
- - [Usage](#usage)
42
- - [KnexModule](#knexmodule)
43
- - [ExampleOfUse](#example-of-use)
44
- - [MultiConnectionsDatabase](#multi-connections-database)
45
- - [CreateMigrations](#create-migrations)
46
- - [RunMigrations](#run-migrations)
47
- - [CreateSeeds](#create-seeds)
48
- - [RunSeeds](#run-seeds)
49
- ## Usage
50
-
51
- ### KnexModule
52
-
53
- KnexModule is the primary entry point for this package and can be used synchronously
54
-
55
- ```typescript
56
- @Module({
57
- imports: [
58
- KnexModule.forRoot({
59
- config: {
60
- client: 'mysql',
61
- version: '5.7',
62
- connection: {
63
- host: '127.0.0.1',
64
- user: 'root',
65
- password: 'root',
66
- database: 'test',
67
- },
68
- },
69
- }),
70
- ],
71
- })
72
- ```
73
- or asynchronously
74
-
75
- ```typescript
76
- @Module({
77
- imports: [
78
- KnexModule.forRootAsync({
79
- useFactory: () => ({
80
- config: {
81
- client: 'mysql',
82
- version: '5.7',
83
- connection: {
84
- host: '127.0.0.1',
85
- user: 'root',
86
- password: 'root',
87
- database: 'test',
88
- },
89
- },
90
- }),
91
- }),
92
- ],
93
- })
94
- ```
95
-
96
- ## Example of use
97
-
98
- UsersService:
99
-
100
- ```typescript
101
- import { Injectable } from '@nestjs/common';
102
- import { Knex } from 'knex';
103
- import { InjectConnection } from 'nest-knexjs';
104
-
105
- @Injectable()
106
- export class UsersService {
107
- constructor(@InjectConnection() private readonly knex: Knex) {}
108
-
109
- async findAll() {
110
- const users = await this.knex.table('users');
111
- return { users };
112
- }
113
- }
114
- ```
115
-
116
- UsersController:
117
-
118
- ```typescript
119
- import { Controller, Get } from '@nestjs/common';
120
- import { UsersService } from './users.service';
121
-
122
- @Controller()
123
- export class UsersController {
124
- constructor(private readonly usersService: UsersService) {}
125
-
126
- @Get()
127
- async getAllUsers() {
128
- return await this.usersService.findAll();
129
- }
130
- }
131
- ```
132
-
133
- ## Multi Connections Database
134
-
135
- ```typescript
136
- @Module({
137
- imports: [
138
- KnexModule.forRootAsync(
139
- {
140
- useFactory: () => ({
141
- config: {
142
- client: 'mysql',
143
- version: '5.7',
144
- useNullAsDefault: true,
145
- connection: {
146
- host: '127.0.0.1',
147
- user: 'root',
148
- port: 3306,
149
- password: 'root',
150
- database: 'test1',
151
- },
152
- pool: {
153
- min: 2,
154
- max: 10,
155
- },
156
- },
157
- }),
158
- },
159
- 'db1Connection',
160
- ),
161
- KnexModule.forRootAsync(
162
- {
163
- useFactory: () => ({
164
- config: {
165
- client: 'mysql',
166
- version: '5.7',
167
- useNullAsDefault: true,
168
- connection: {
169
- host: '127.0.0.1',
170
- user: 'root',
171
- port: 3307,
172
- password: 'root',
173
- database: 'test2',
174
- },
175
- pool: {
176
- min: 2,
177
- max: 10,
178
- },
179
- },
180
- }),
181
- },
182
- 'db2Connection',
183
- ),
184
- ],
185
- controllers: [],
186
- providers: [],
187
- })
188
- export class AppModule {}
189
- ```
190
-
191
- Usage example with Multi Connection
192
-
193
- PostService:
194
-
195
- ```typescript
196
- @Injectable()
197
- export class PostService {
198
- constructor(
199
- @InjectConnection('db2Connection')
200
- private knexConnection: Knex,
201
- ) {}
202
-
203
- async create(createPostDto: CreatePostDto) {
204
- try {
205
- const post = await this.knexConnection.table('posts').insert({
206
- title: createPostDto.title,
207
- description: createPostDto.description,
208
- });
209
-
210
- return post;
211
- } catch (err) {
212
- throw new HttpException(err, HttpStatus.BAD_REQUEST);
213
- }
214
- }
215
-
216
- async findAll() {
217
- const posts = await this.knexConnection.table('posts');
218
- return { posts };
219
- }
220
- }
221
- ```
222
-
223
- UsersService:
224
-
225
- ```typescript
226
- @Injectable()
227
- export class UsersService {
228
- constructor(
229
- @InjectConnection('db1Connection')
230
- private knexConnection: Knex,
231
- ) {}
232
-
233
- async findAll() {
234
- const users = await this.knexConnection.table('users');
235
- return { users };
236
- }
237
-
238
- async create(createUserDto: CreateUserDto) {
239
- try {
240
- const users = await this.knexConnection.table('users').insert({
241
- firstName: createUserDto.firstName,
242
- lastName: createUserDto.lastName,
243
- });
244
-
245
- return { users };
246
- } catch (err) {
247
- throw new HttpException(err, HttpStatus.BAD_REQUEST);
248
- }
249
- }
250
- }
251
- ```
252
-
253
-
254
- In `knexfile.js` update with your database configuration settings:
255
-
256
- ```javascript
257
- module.exports = {
258
- development: {
259
- client: 'mysql',
260
- version: '5.7',
261
- connection: {
262
- name: 'db1Connection',
263
- host: '127.0.0.1',
264
- user: 'root',
265
- port: 3306,
266
- password: 'root',
267
- database: 'test1',
268
- },
269
- migrations: {
270
- directory: './migrations/users',
271
- tableName: '[:name_file_migrations_users]',
272
- },
273
- },
274
- developmentTwo: {
275
- client: 'mysql',
276
- version: '5.7',
277
- connection: {
278
- name: 'db2Connection',
279
- host: '127.0.0.1',
280
- user: 'root',
281
- port: 3307,
282
- password: 'root',
283
- database: 'test2',
284
- },
285
- migrations: {
286
- directory: './migrations/posts',
287
- tableName: '[:name_file_migrations_posts]',
288
- },
289
- },
290
- };
291
- ```
292
-
293
- Run Migrations:
294
-
295
- ```bash
296
- $ npx knex migrate:latest --env development
297
-
298
- $ npx knex migrate:latest --env developmentTwo
299
- ```
300
-
301
- ## Create Migrations
302
-
303
- ```bash
304
- $ npx knex init
305
- $ npx knex migrate:make [name_migrations]
306
- ```
307
-
308
- Example file migrations:
309
-
310
- ```typescript
311
- exports.up = function(knex) {
312
- return knex.schema
313
- .createTable('users', function(table) {
314
- table.increments('id');
315
- table.string('firstName', 255).notNullable();
316
- table.string('lastName', 255).notNullable();
317
- })
318
- .createTable('products', function(table) {
319
- table.increments('id');
320
- table.string('name', 255).notNullable();
321
- table.decimal('price').notNullable();
322
- });
323
- };
324
-
325
- exports.down = function (knex) {
326
- return knex.schema.dropTable('products').dropTable('users');
327
- };
328
- ```
329
-
330
- ## Run Migrations
331
-
332
- In `knexfile.js` update with your config settings:
333
-
334
- ```javascript
335
- module.exports = {
336
- development: {
337
- client: 'mysql',
338
- connection: {
339
- host: '127.0.0.1',
340
- user: 'root',
341
- password: 'root',
342
- database: 'test',
343
- },
344
- },
345
- }
346
- ```
347
-
348
- then we run the following command from the terminal
349
-
350
- ```bash
351
- $ npx knex migrate:latest
352
- ```
353
-
354
- ## Create Seeds
355
-
356
- ```bash
357
- $ npx knex seed:make [name_seed]
358
- ```
359
-
360
- Example file seeds
361
-
362
- ```javascript
363
- exports.seed = function (knex) {
364
- return knex('users')
365
- .del()
366
- .then(function () {
367
- return knex('users').insert([
368
- { id: 1, firstName: 'firstName#1', lastName: 'lastName#1' },
369
- { id: 2, firstName: 'firstName#2', lastName: 'lastName#2' },
370
- { id: 3, firstName: 'firstName#3', lastName: 'lastName#3' },
371
- ]);
372
- });
373
- };
374
- ```
375
-
376
- ## Run Seeds
377
-
378
- ```
379
- $ npx knex seed:run
380
- ```
381
-
382
- For more information on `Knex.js` see [here](http://knexjs.org/)
383
-
384
- ## Contribute
385
- Feel free to help this library, I'm quite busy with also another Nestjs packages, but the community will appreciate the effort of improving this library. Make sure you follow the guidelines
386
-
387
- ## Stay in touch
388
-
389
- - Author - [Tony133](https://github.com/Tony133)
390
- - Framework - [https://nestjs.com](https://nestjs.com/)
391
-
392
- ## License
393
-
394
- [MIT licensed](LICENSE)
3
+ ⚠️ DEPRECATED - This package is no longer maintained. Please use the official knex package instead.
package/_README.md ADDED
@@ -0,0 +1,406 @@
1
+ # nest-knexjs
2
+
3
+ ---
4
+
5
+ ⚠️ **DEPRECATED** ⚠️ - This package is no longer maintained
6
+
7
+ ---
8
+
9
+ ## Description
10
+
11
+ Knexjs module for Nest framework (node.js)
12
+
13
+ ## Installation
14
+
15
+ First install the module via `yarn` or `npm` or `pnpm` and do not forget to install the driver package as well:
16
+
17
+ ```bash
18
+ npm i --save nest-knexjs knex mysql # for mysql/mariadb
19
+ npm i --save nest-knexjs knex pg # for postgresql
20
+ npm i --save nest-knexjs knex sqlite # for sqlite
21
+ npm i --save nest-knexjs knex oracledb # for oracledb
22
+ ```
23
+
24
+ or
25
+
26
+ ```bash
27
+ yarn add nest-knexjs knex mysql # for mysql/mariadb
28
+ yarn add nest-knexjs knex pg # for postgresql
29
+ yarn add nest-knexjs knex sqlite # for sqlite
30
+ yarn add nest-knexjs knex oracledb # for oracledb
31
+ ```
32
+
33
+ or
34
+
35
+ ```bash
36
+ pnpm add nest-knexjs knex mysql # for mysql/mariadb
37
+ pnpm add nest-knexjs knex pg # for postgresql
38
+ pnpm add nest-knexjs knex sqlite # for sqlite
39
+ pnpm add nest-knexjs knex oracledb # for oracledb
40
+ ```
41
+
42
+ ## Table of Contents
43
+
44
+ - [nest-knexjs](#nest-knexjs)
45
+ - [Description](#description)
46
+ - [Installation](#installation)
47
+ - [Table of Contents](#table-of-contents)
48
+ - [Usage](#usage)
49
+ - [KnexModule](#knexmodule)
50
+ - [Example of use](#example-of-use)
51
+ - [Multi Connections Database](#multi-connections-database)
52
+ - [Create Migrations](#create-migrations)
53
+ - [Run Migrations](#run-migrations)
54
+ - [Create Seeds](#create-seeds)
55
+ - [Run Seeds](#run-seeds)
56
+ - [Contribute](#contribute)
57
+ - [Stay in touch](#stay-in-touch)
58
+ - [License](#license)
59
+
60
+ ## Usage
61
+
62
+ ### KnexModule
63
+
64
+ KnexModule is the primary entry point for this package and can be used synchronously
65
+
66
+ ```typescript
67
+ @Module({
68
+ imports: [
69
+ KnexModule.forRoot({
70
+ config: {
71
+ client: 'mysql',
72
+ version: '5.7',
73
+ connection: {
74
+ host: '127.0.0.1',
75
+ user: 'root',
76
+ password: 'root',
77
+ database: 'test',
78
+ },
79
+ },
80
+ }),
81
+ ],
82
+ })
83
+ ```
84
+
85
+ or asynchronously
86
+
87
+ ```typescript
88
+ @Module({
89
+ imports: [
90
+ KnexModule.forRootAsync({
91
+ useFactory: () => ({
92
+ config: {
93
+ client: 'mysql',
94
+ version: '5.7',
95
+ connection: {
96
+ host: '127.0.0.1',
97
+ user: 'root',
98
+ password: 'root',
99
+ database: 'test',
100
+ },
101
+ },
102
+ }),
103
+ }),
104
+ ],
105
+ })
106
+ ```
107
+
108
+ ## Example of use
109
+
110
+ UsersService:
111
+
112
+ ```typescript
113
+ import { Injectable } from '@nestjs/common';
114
+ import { Knex } from 'knex';
115
+ import { InjectConnection } from 'nest-knexjs';
116
+
117
+ @Injectable()
118
+ export class UsersService {
119
+ constructor(@InjectConnection() private readonly knex: Knex) {}
120
+
121
+ async findAll() {
122
+ const users = await this.knex.table('users');
123
+ return { users };
124
+ }
125
+ }
126
+ ```
127
+
128
+ UsersController:
129
+
130
+ ```typescript
131
+ import { Controller, Get } from '@nestjs/common';
132
+ import { UsersService } from './users.service';
133
+
134
+ @Controller()
135
+ export class UsersController {
136
+ constructor(private readonly usersService: UsersService) {}
137
+
138
+ @Get()
139
+ async getAllUsers() {
140
+ return await this.usersService.findAll();
141
+ }
142
+ }
143
+ ```
144
+
145
+ ## Multi Connections Database
146
+
147
+ ```typescript
148
+ @Module({
149
+ imports: [
150
+ KnexModule.forRootAsync(
151
+ {
152
+ useFactory: () => ({
153
+ config: {
154
+ client: 'mysql',
155
+ version: '5.7',
156
+ useNullAsDefault: true,
157
+ connection: {
158
+ host: '127.0.0.1',
159
+ user: 'root',
160
+ port: 3306,
161
+ password: 'root',
162
+ database: 'test1',
163
+ },
164
+ pool: {
165
+ min: 2,
166
+ max: 10,
167
+ },
168
+ },
169
+ }),
170
+ },
171
+ 'db1Connection',
172
+ ),
173
+ KnexModule.forRootAsync(
174
+ {
175
+ useFactory: () => ({
176
+ config: {
177
+ client: 'mysql',
178
+ version: '5.7',
179
+ useNullAsDefault: true,
180
+ connection: {
181
+ host: '127.0.0.1',
182
+ user: 'root',
183
+ port: 3307,
184
+ password: 'root',
185
+ database: 'test2',
186
+ },
187
+ pool: {
188
+ min: 2,
189
+ max: 10,
190
+ },
191
+ },
192
+ }),
193
+ },
194
+ 'db2Connection',
195
+ ),
196
+ ],
197
+ controllers: [],
198
+ providers: [],
199
+ })
200
+ export class AppModule {}
201
+ ```
202
+
203
+ Usage example with Multi Connection
204
+
205
+ PostService:
206
+
207
+ ```typescript
208
+ @Injectable()
209
+ export class PostService {
210
+ constructor(
211
+ @InjectConnection('db2Connection')
212
+ private knexConnection: Knex,
213
+ ) {}
214
+
215
+ async create(createPostDto: CreatePostDto) {
216
+ try {
217
+ const post = await this.knexConnection.table('posts').insert({
218
+ title: createPostDto.title,
219
+ description: createPostDto.description,
220
+ });
221
+
222
+ return post;
223
+ } catch (err) {
224
+ throw new HttpException(err, HttpStatus.BAD_REQUEST);
225
+ }
226
+ }
227
+
228
+ async findAll() {
229
+ const posts = await this.knexConnection.table('posts');
230
+ return { posts };
231
+ }
232
+ }
233
+ ```
234
+
235
+ UsersService:
236
+
237
+ ```typescript
238
+ @Injectable()
239
+ export class UsersService {
240
+ constructor(
241
+ @InjectConnection('db1Connection')
242
+ private knexConnection: Knex,
243
+ ) {}
244
+
245
+ async findAll() {
246
+ const users = await this.knexConnection.table('users');
247
+ return { users };
248
+ }
249
+
250
+ async create(createUserDto: CreateUserDto) {
251
+ try {
252
+ const users = await this.knexConnection.table('users').insert({
253
+ firstName: createUserDto.firstName,
254
+ lastName: createUserDto.lastName,
255
+ });
256
+
257
+ return { users };
258
+ } catch (err) {
259
+ throw new HttpException(err, HttpStatus.BAD_REQUEST);
260
+ }
261
+ }
262
+ }
263
+ ```
264
+
265
+ In `knexfile.js` update with your database configuration settings:
266
+
267
+ ```javascript
268
+ module.exports = {
269
+ development: {
270
+ client: 'mysql',
271
+ version: '5.7',
272
+ connection: {
273
+ name: 'db1Connection',
274
+ host: '127.0.0.1',
275
+ user: 'root',
276
+ port: 3306,
277
+ password: 'root',
278
+ database: 'test1',
279
+ },
280
+ migrations: {
281
+ directory: './migrations/users',
282
+ tableName: '[:name_file_migrations_users]',
283
+ },
284
+ },
285
+ developmentTwo: {
286
+ client: 'mysql',
287
+ version: '5.7',
288
+ connection: {
289
+ name: 'db2Connection',
290
+ host: '127.0.0.1',
291
+ user: 'root',
292
+ port: 3307,
293
+ password: 'root',
294
+ database: 'test2',
295
+ },
296
+ migrations: {
297
+ directory: './migrations/posts',
298
+ tableName: '[:name_file_migrations_posts]',
299
+ },
300
+ },
301
+ };
302
+ ```
303
+
304
+ Run Migrations:
305
+
306
+ ```bash
307
+ npx knex migrate:latest --env development
308
+
309
+ npx knex migrate:latest --env developmentTwo
310
+ ```
311
+
312
+ ## Create Migrations
313
+
314
+ ```bash
315
+ npx knex init
316
+ npx knex migrate:make [name_migrations]
317
+ ```
318
+
319
+ Example file migrations:
320
+
321
+ ```typescript
322
+ exports.up = function(knex) {
323
+ return knex.schema
324
+ .createTable('users', function(table) {
325
+ table.increments('id');
326
+ table.string('firstName', 255).notNullable();
327
+ table.string('lastName', 255).notNullable();
328
+ })
329
+ .createTable('products', function(table) {
330
+ table.increments('id');
331
+ table.string('name', 255).notNullable();
332
+ table.decimal('price').notNullable();
333
+ });
334
+ };
335
+
336
+ exports.down = function (knex) {
337
+ return knex.schema.dropTable('products').dropTable('users');
338
+ };
339
+ ```
340
+
341
+ ## Run Migrations
342
+
343
+ In `knexfile.js` update with your config settings:
344
+
345
+ ```javascript
346
+ module.exports = {
347
+ development: {
348
+ client: 'mysql',
349
+ connection: {
350
+ host: '127.0.0.1',
351
+ user: 'root',
352
+ password: 'root',
353
+ database: 'test',
354
+ },
355
+ },
356
+ }
357
+ ```
358
+
359
+ then we run the following command from the terminal
360
+
361
+ ```bash
362
+ npx knex migrate:latest
363
+ ```
364
+
365
+ ## Create Seeds
366
+
367
+ ```bash
368
+ npx knex seed:make [name_seed]
369
+ ```
370
+
371
+ Example file seeds
372
+
373
+ ```javascript
374
+ exports.seed = function (knex) {
375
+ return knex('users')
376
+ .del()
377
+ .then(function () {
378
+ return knex('users').insert([
379
+ { id: 1, firstName: 'firstName#1', lastName: 'lastName#1' },
380
+ { id: 2, firstName: 'firstName#2', lastName: 'lastName#2' },
381
+ { id: 3, firstName: 'firstName#3', lastName: 'lastName#3' },
382
+ ]);
383
+ });
384
+ };
385
+ ```
386
+
387
+ ## Run Seeds
388
+
389
+ ```
390
+ npx knex seed:run
391
+ ```
392
+
393
+ For more information on `Knex.js` see [here](http://knexjs.org/)
394
+
395
+ ## Contribute
396
+
397
+ Feel free to help this library, I'm quite busy with also another Nestjs packages, but the community will appreciate the effort of improving this library. Make sure you follow the guidelines
398
+
399
+ ## Stay in touch
400
+
401
+ - Author - [Tony133](https://github.com/Tony133)
402
+ - Framework - [https://nestjs.com](https://nestjs.com/)
403
+
404
+ ## License
405
+
406
+ [MIT licensed](LICENSE)
package/package.json CHANGED
@@ -1,9 +1,7 @@
1
1
  {
2
2
  "name": "nest-knexjs",
3
- "version": "0.0.30",
4
- "description": "Knexjs module for Nest framework (node.js)",
5
- "author": "Tony133",
6
- "license": "MIT",
3
+ "version": "0.0.32",
4
+ "description": "⚠️ DEPRECATED - This package is no longer maintained. Please use the official knex package instead.",
7
5
  "scripts": {
8
6
  "build": "rm -rf dist && tsc -p tsconfig.json",
9
7
  "format": "prettier --write \"**/*.ts\"",
@@ -18,18 +16,18 @@
18
16
  "prepare": "husky"
19
17
  },
20
18
  "devDependencies": {
21
- "@commitlint/cli": "20.4.1",
22
- "@commitlint/config-angular": "20.4.1",
19
+ "@commitlint/cli": "20.4.2",
20
+ "@commitlint/config-angular": "20.4.2",
23
21
  "@eslint/eslintrc": "3.3.3",
24
- "@eslint/js": "9.39.2",
25
- "@nestjs/common": "11.1.13",
26
- "@nestjs/core": "11.1.13",
27
- "@nestjs/platform-fastify": "11.1.13",
28
- "@nestjs/testing": "11.1.13",
22
+ "@eslint/js": "9.39.3",
23
+ "@nestjs/common": "11.1.14",
24
+ "@nestjs/core": "11.1.14",
25
+ "@nestjs/platform-fastify": "11.1.14",
26
+ "@nestjs/testing": "11.1.14",
29
27
  "@types/jest": "30.0.0",
30
28
  "@types/node": "24.10.13",
31
29
  "@types/supertest": "6.0.3",
32
- "eslint": "9.39.2",
30
+ "eslint": "9.39.3",
33
31
  "eslint-config-prettier": "10.1.8",
34
32
  "eslint-plugin-import": "2.32.0",
35
33
  "eslint-plugin-prettier": "5.5.5",
@@ -57,9 +55,5 @@
57
55
  },
58
56
  "lint-staged": {
59
57
  "**/*.{ts,json}": []
60
- },
61
- "repository": {
62
- "type": "git",
63
- "url": "https://github.com/tony133/nestjs-knexjs"
64
58
  }
65
59
  }