@tc-libs/database 3.6.0 → 3.6.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 +85 -6
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,11 +1,90 @@
|
|
|
1
|
-
# database
|
|
1
|
+
# @tc-libs/database
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Layer base Mongo/Mongoose del monorepo.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Il package contiene:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- `DatabaseOptionsModule` per costruire `MongooseModuleOptions`
|
|
8
|
+
- abstract entity/repository riusabili
|
|
9
|
+
- interfacce per query, sessioni, cache e pagination
|
|
10
|
+
- costanti e decorator di supporto
|
|
8
11
|
|
|
9
|
-
##
|
|
12
|
+
## `DatabaseOptionsModule`
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
Serve per centralizzare la costruzione della connection string Mongo:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
DatabaseOptionsModule.register({
|
|
18
|
+
proto: 'mongodb',
|
|
19
|
+
host: '127.0.0.1:27017',
|
|
20
|
+
port: 27017,
|
|
21
|
+
name: 'mydb',
|
|
22
|
+
user: 'mongo',
|
|
23
|
+
password: 'secret',
|
|
24
|
+
debug: false,
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Poi:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
MongooseModule.forRootAsync({
|
|
32
|
+
imports: [DatabaseOptionsModule.register(...)],
|
|
33
|
+
useExisting: DatabaseOptionsService,
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Repository base
|
|
38
|
+
|
|
39
|
+
La classe piu importante e `DatabaseMongoRepositoryAbstract<Entity, EntityDocument>`.
|
|
40
|
+
|
|
41
|
+
Fornisce:
|
|
42
|
+
|
|
43
|
+
- CRUD standard
|
|
44
|
+
- join/populate opzionale
|
|
45
|
+
- `returnPlain`
|
|
46
|
+
- supporto `ClientSession`
|
|
47
|
+
- integrazione cache con `@tc-libs/app-cache`
|
|
48
|
+
- `raw()` per aggregate pipeline
|
|
49
|
+
- `startTransaction()`
|
|
50
|
+
|
|
51
|
+
## Esempio repository custom
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
export class UserRepository extends DatabaseMongoRepositoryAbstract<
|
|
55
|
+
UserEntity,
|
|
56
|
+
UserDoc
|
|
57
|
+
> {
|
|
58
|
+
protected readonly _logger = new Logger(UserRepository.name);
|
|
59
|
+
|
|
60
|
+
constructor(
|
|
61
|
+
@InjectModel(UserEntity.name) model: Model<UserEntity>,
|
|
62
|
+
@InjectConnection() connection: Connection,
|
|
63
|
+
cache: AppCacheService,
|
|
64
|
+
) {
|
|
65
|
+
super(model, connection, cache);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Abstract entity
|
|
71
|
+
|
|
72
|
+
- `DatabaseBaseEntityAbstract`
|
|
73
|
+
- `DatabaseMongoEntityAbstract`
|
|
74
|
+
|
|
75
|
+
Ti evitano di ridefinire sempre `_id`, `createdAt`, `updatedAt`.
|
|
76
|
+
|
|
77
|
+
## Interfacce piu usate
|
|
78
|
+
|
|
79
|
+
- `IDatabaseFindOneOptions`
|
|
80
|
+
- `IDatabaseFindAllOptions`
|
|
81
|
+
- `IDatabaseCreateOptions`
|
|
82
|
+
- `IDatabaseManyOptions`
|
|
83
|
+
- `IDatabaseFindOneAndUpdateOptions`
|
|
84
|
+
|
|
85
|
+
## Sviluppo
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
nx build database
|
|
89
|
+
nx test database
|
|
90
|
+
```
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tc-libs/database",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@tc-libs/app-cache": "3.6.
|
|
6
|
-
"@tc-libs/pagination": "3.6.
|
|
5
|
+
"@tc-libs/app-cache": "3.6.1",
|
|
6
|
+
"@tc-libs/pagination": "3.6.1",
|
|
7
7
|
"@nestjs/mongoose": "^11.0.3",
|
|
8
8
|
"mongoose": "^8.13.1",
|
|
9
9
|
"@nestjs/common": "^11.0.12",
|