@rws-framework/db 2.3.2 → 2.4.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.
Files changed (92) hide show
  1. package/.bin/add-v.sh +9 -9
  2. package/.bin/emerge.sh +10 -10
  3. package/.eslintrc.json +53 -53
  4. package/README.md +404 -367
  5. package/dist/decorators/InverseRelation.d.ts +12 -12
  6. package/dist/decorators/InverseRelation.js +24 -24
  7. package/dist/decorators/InverseTimeSeries.d.ts +8 -8
  8. package/dist/decorators/InverseTimeSeries.js +13 -13
  9. package/dist/decorators/RWSCollection.d.ts +12 -12
  10. package/dist/decorators/RWSCollection.js +16 -16
  11. package/dist/decorators/Relation.d.ts +19 -19
  12. package/dist/decorators/Relation.js +26 -26
  13. package/dist/decorators/TrackType.d.ts +20 -20
  14. package/dist/decorators/TrackType.js +41 -41
  15. package/dist/decorators/index.d.ts +5 -5
  16. package/dist/decorators/index.js +14 -14
  17. package/dist/helper/DbHelper.d.ts +8 -8
  18. package/dist/helper/DbHelper.js +141 -141
  19. package/dist/helper/FieldsHelper.d.ts +4 -4
  20. package/dist/helper/FieldsHelper.js +35 -35
  21. package/dist/index.d.ts +12 -12
  22. package/dist/index.js +19 -19
  23. package/dist/models/TimeSeriesModel.d.ts +7 -7
  24. package/dist/models/TimeSeriesModel.js +33 -33
  25. package/dist/models/_model.d.ts +6 -6
  26. package/dist/models/_model.js +9 -9
  27. package/dist/models/core/RWSModel.d.ts +66 -66
  28. package/dist/models/core/RWSModel.js +400 -400
  29. package/dist/models/core/TimeSeriesModel.d.ts +1 -1
  30. package/dist/models/core/TimeSeriesModel.js +14 -14
  31. package/dist/models/index.d.ts +7 -7
  32. package/dist/models/index.js +8 -8
  33. package/dist/models/interfaces/IModel.d.ts +11 -11
  34. package/dist/models/interfaces/IModel.js +2 -2
  35. package/dist/models/interfaces/IRWSModelServices.d.ts +6 -6
  36. package/dist/models/interfaces/IRWSModelServices.js +2 -2
  37. package/dist/models/interfaces/OpModelType.d.ts +31 -31
  38. package/dist/models/interfaces/OpModelType.js +2 -2
  39. package/dist/models/types/RelationTypes.d.ts +24 -24
  40. package/dist/models/types/RelationTypes.js +2 -2
  41. package/dist/models/utils/ModelUtils.d.ts +10 -10
  42. package/dist/models/utils/ModelUtils.js +56 -56
  43. package/dist/models/utils/PaginationUtils.d.ts +5 -5
  44. package/dist/models/utils/PaginationUtils.js +32 -32
  45. package/dist/models/utils/RelationUtils.d.ts +14 -14
  46. package/dist/models/utils/RelationUtils.js +65 -65
  47. package/dist/models/utils/TimeSeriesUtils.d.ts +11 -11
  48. package/dist/models/utils/TimeSeriesUtils.js +35 -35
  49. package/dist/services/DBService.d.ts +37 -37
  50. package/dist/services/DBService.js +198 -198
  51. package/dist/types/DbConfigHandler.d.ts +9 -9
  52. package/dist/types/DbConfigHandler.js +2 -2
  53. package/dist/types/FindParams.d.ts +14 -14
  54. package/dist/types/FindParams.js +2 -2
  55. package/dist/types/IRWSModel.d.ts +3 -3
  56. package/dist/types/IRWSModel.js +2 -2
  57. package/dist/types/ITimeSeries.d.ts +6 -6
  58. package/dist/types/ITimeSeries.js +2 -2
  59. package/exec/console.js +110 -110
  60. package/exec/db.rws.webpack.config.js +168 -168
  61. package/exec/src/cli.ts +74 -73
  62. package/exec/tsconfig.json +32 -32
  63. package/exec/webpackFilters.js +17 -17
  64. package/package.json +36 -36
  65. package/src/decorators/InverseRelation.ts +36 -36
  66. package/src/decorators/InverseTimeSeries.ts +21 -21
  67. package/src/decorators/RWSCollection.ts +27 -27
  68. package/src/decorators/Relation.ts +47 -47
  69. package/src/decorators/TrackType.ts +69 -69
  70. package/src/decorators/index.ts +7 -7
  71. package/src/empty.js +0 -0
  72. package/src/helper/DbHelper.ts +177 -177
  73. package/src/helper/FieldsHelper.ts +34 -34
  74. package/src/index.ts +36 -36
  75. package/src/models/_model.ts +29 -29
  76. package/src/models/core/RWSModel.ts +520 -520
  77. package/src/models/core/TimeSeriesModel.ts +19 -19
  78. package/src/models/index.ts +20 -20
  79. package/src/models/interfaces/IModel.ts +12 -12
  80. package/src/models/interfaces/IRWSModelServices.ts +7 -7
  81. package/src/models/interfaces/OpModelType.ts +49 -49
  82. package/src/models/types/RelationTypes.ts +25 -25
  83. package/src/models/utils/ModelUtils.ts +65 -65
  84. package/src/models/utils/PaginationUtils.ts +42 -42
  85. package/src/models/utils/RelationUtils.ts +76 -76
  86. package/src/models/utils/TimeSeriesUtils.ts +38 -38
  87. package/src/services/DBService.ts +277 -277
  88. package/src/types/DbConfigHandler.ts +12 -11
  89. package/src/types/FindParams.ts +13 -13
  90. package/src/types/IRWSModel.ts +2 -2
  91. package/src/types/ITimeSeries.ts +5 -5
  92. package/tsconfig.json +22 -22
@@ -1,38 +1,38 @@
1
- import { RWSModel } from "../_model";
2
-
3
- export class TimeSeriesUtils {
4
- static getTimeSeriesModelFields(model: RWSModel<any>): {[key: string]: {collection: string, hydrationField: string, ids: string[]}} {
5
- const timeSeriesIds: {[key: string]: {collection: string, hydrationField: string, ids: string[]}} = {};
6
-
7
- for (const key in model) {
8
- if (model.hasOwnProperty(key)) {
9
- const meta = Reflect.getMetadata(`InverseTimeSeries:${key}`, model);
10
- if(meta){
11
- if(!timeSeriesIds[key]){
12
- timeSeriesIds[key] = {
13
- collection: meta.timeSeriesModel,
14
- hydrationField: meta.hydrationField,
15
- ids: model[key]
16
- };
17
- }
18
- }
19
- }
20
- }
21
-
22
- return timeSeriesIds;
23
- }
24
-
25
- static checkTimeSeries(constructor: any): boolean {
26
- const data = constructor.prototype as any;
27
-
28
- for (const key in data) {
29
- if (data.hasOwnProperty(key)) {
30
- if(Reflect.getMetadata(`InverseTimeSeries:${key}`, constructor.prototype)){
31
- return true;
32
- }
33
- }
34
- }
35
-
36
- return false;
37
- }
38
- }
1
+ import { RWSModel } from "../_model";
2
+
3
+ export class TimeSeriesUtils {
4
+ static getTimeSeriesModelFields(model: RWSModel<any>): {[key: string]: {collection: string, hydrationField: string, ids: string[]}} {
5
+ const timeSeriesIds: {[key: string]: {collection: string, hydrationField: string, ids: string[]}} = {};
6
+
7
+ for (const key in model) {
8
+ if (model.hasOwnProperty(key)) {
9
+ const meta = Reflect.getMetadata(`InverseTimeSeries:${key}`, model);
10
+ if(meta){
11
+ if(!timeSeriesIds[key]){
12
+ timeSeriesIds[key] = {
13
+ collection: meta.timeSeriesModel,
14
+ hydrationField: meta.hydrationField,
15
+ ids: model[key]
16
+ };
17
+ }
18
+ }
19
+ }
20
+ }
21
+
22
+ return timeSeriesIds;
23
+ }
24
+
25
+ static checkTimeSeries(constructor: any): boolean {
26
+ const data = constructor.prototype as any;
27
+
28
+ for (const key in data) {
29
+ if (data.hasOwnProperty(key)) {
30
+ if(Reflect.getMetadata(`InverseTimeSeries:${key}`, constructor.prototype)){
31
+ return true;
32
+ }
33
+ }
34
+ }
35
+
36
+ return false;
37
+ }
38
+ }
@@ -1,277 +1,277 @@
1
- import { PrismaClient } from '@prisma/client';
2
- import { Collection, Db, MongoClient } from 'mongodb';
3
- import {ITimeSeries} from '../types/ITimeSeries';
4
- import { IModel } from '../models/interfaces/IModel';
5
- import chalk from 'chalk';
6
- import { IDbConfigHandler } from '../types/DbConfigHandler';
7
- import { IPaginationParams } from '../types/FindParams';
8
-
9
- interface IDBClientCreate {
10
- dbUrl?: string;
11
- dbName?: string;
12
- }
13
-
14
- class DBService {
15
- private client: PrismaClient;
16
- private opts: IDBClientCreate = null;
17
- private connected = false;
18
-
19
- constructor(private configService: IDbConfigHandler){}
20
-
21
- private connectToDB(opts: IDBClientCreate = null) {
22
- if(opts){
23
- this.opts = opts;
24
- }else{
25
- this.opts = {
26
- dbUrl: this.configService.get('mongo_url'),
27
- dbName: this.configService.get('mongo_db'),
28
- };
29
- }
30
-
31
- if(!this.opts.dbUrl){
32
- console.log(chalk.red('No database config set in @rws-framework/db'));
33
-
34
- return;
35
- }
36
-
37
- try{
38
- this.client = new PrismaClient({
39
- datasources: {
40
- db: {
41
- url: this.opts.dbUrl
42
- },
43
- },
44
- });
45
-
46
- this.connected = true;
47
- } catch (e: Error | any){
48
- console.error(e);
49
-
50
- throw new Error('PRISMA CONNECTION ERROR');
51
- }
52
- }
53
-
54
- reconnect(opts: IDBClientCreate = null)
55
- {
56
- this.connectToDB(opts);
57
- }
58
-
59
- static baseClientConstruct(dbUrl: string): MongoClient
60
- {
61
- const client = new MongoClient(dbUrl);
62
-
63
- return client;
64
- }
65
-
66
- public async createBaseMongoClient(): Promise<MongoClient>
67
- {
68
- const dbUrl = this.opts?.dbUrl || this.configService.get('mongo_url');
69
- const client = DBService.baseClientConstruct(dbUrl);
70
-
71
- await client.connect();
72
-
73
- return client;
74
-
75
- }
76
-
77
- public async createBaseMongoClientDB(): Promise<[MongoClient, Db]>
78
- {
79
- const dbName = this.opts?.dbName || this.configService.get('mongo_db');
80
- const client = await this.createBaseMongoClient();
81
- return [client, client.db(dbName)];
82
- }
83
-
84
- public async cloneDatabase(source: string, target: string): Promise<void> {
85
- const client = await this.createBaseMongoClient();
86
-
87
- // Source and target DB
88
- const sourceDb = client.db(source);
89
- const targetDb = client.db(target);
90
-
91
- // Get all collections from source DB
92
- const collections = await sourceDb.listCollections().toArray();
93
-
94
- // Loop over all collections and copy them to the target DB
95
- for (const collection of collections) {
96
- const docs = await sourceDb.collection(collection.name).find({}).toArray();
97
- await targetDb.collection(collection.name).insertMany(docs);
98
- }
99
-
100
- await client.close();
101
- }
102
-
103
- async watchCollection(collectionName: string, preRun: () => void): Promise<any>
104
- {
105
- const [client, db] = await this.createBaseMongoClientDB();
106
- const collection = db.collection(collectionName);
107
-
108
- const changeStream = collection.watch();
109
- return new Promise((resolve) => {
110
- changeStream.on('change', (change) => {
111
- resolve(change);
112
- });
113
-
114
- preRun();
115
- });
116
- }
117
-
118
- async insert(data: any, collection: string, isTimeSeries: boolean = false) {
119
-
120
- let result: any = data;
121
- // Insert time-series data outside of the transaction
122
-
123
- if(isTimeSeries){
124
- const [client, db] = await this.createBaseMongoClientDB();
125
- const collectionHandler = db.collection(collection);
126
-
127
- const insert = await collectionHandler.insertOne(data);
128
-
129
- result = await this.findOneBy(collection, { id: insert.insertedId.toString() });
130
- return result;
131
- }
132
-
133
- const prismaCollection = this.getCollectionHandler(collection);
134
-
135
- result = await prismaCollection.create({ data });
136
-
137
- return await this.findOneBy(collection, { id: result.id });
138
- }
139
-
140
- async update(data: any, collection: string): Promise<IModel>
141
- {
142
- const model_id: string = data.id;
143
- delete data['id'];
144
-
145
- const prismaCollection = this.getCollectionHandler(collection);
146
-
147
- await prismaCollection.update({
148
- where: {
149
- id: model_id,
150
- },
151
- data: data,
152
- });
153
-
154
-
155
- return await this.findOneBy(collection, { id: model_id });
156
- }
157
-
158
-
159
- async findOneBy(collection: string, conditions: any, fields: string[] | null = null, ordering: { [fieldName: string]: string } = null, allowRelations: boolean = true): Promise<IModel|null>
160
- {
161
- const params: any = { where: conditions };
162
-
163
- if(fields){
164
- params.select = {};
165
- fields.forEach((fieldName: string) => {
166
- params.select[fieldName] = true;
167
- });
168
- }
169
-
170
- if(ordering){
171
- params.orderBy = ordering;
172
- }
173
-
174
- const retData = await this.getCollectionHandler(collection).findFirst(params);
175
-
176
- return retData;
177
- }
178
-
179
- async delete(collection: string, conditions: any): Promise<void>
180
- {
181
- await this.getCollectionHandler(collection).deleteMany({ where: conditions });
182
- return;
183
- }
184
-
185
- async findBy(
186
- collection: string,
187
- conditions: any,
188
- fields: string[] | null = null,
189
- ordering: { [fieldName: string]: string } = null,
190
- pagination: IPaginationParams = null): Promise<IModel[]>
191
- {
192
- const params: any ={ where: conditions };
193
-
194
- if(fields){
195
- params.select = {};
196
- fields.forEach((fieldName: string) => {
197
- params.select[fieldName] = true;
198
- });
199
- }
200
-
201
- if(ordering){
202
- params.orderBy = ordering;
203
- }
204
-
205
- if(pagination){
206
- const perPage = pagination.per_page || 50;
207
- params.skip = (pagination.page || 0) * perPage;
208
- params.take = perPage;
209
- }
210
-
211
- const retData = await this.getCollectionHandler(collection).findMany(params);
212
-
213
- return retData;
214
- }
215
-
216
- async collectionExists(collection_name: string): Promise<boolean>
217
- {
218
- const dbUrl = this.opts?.dbUrl || this.configService.get('mongo_url');
219
- const client = new MongoClient(dbUrl);
220
-
221
- try {
222
- await client.connect();
223
-
224
- const db = client.db(this.configService.get('mongo_db'));
225
-
226
- const collections = await db.listCollections().toArray();
227
- const existingCollectionNames = collections.map((collection) => collection.name);
228
-
229
- return existingCollectionNames.includes(collection_name);
230
- } catch (error) {
231
- console.error('Error connecting to MongoDB:', error);
232
-
233
- throw error;
234
- }
235
- }
236
-
237
- async createTimeSeriesCollection(collection_name: string): Promise<Collection<ITimeSeries>>
238
- {
239
- try {
240
- const [client, db] = await this.createBaseMongoClientDB();
241
-
242
- // Create a time series collection
243
- const options = {
244
- timeseries: {
245
- timeField: 'timestamp', // Replace with your timestamp field
246
- metaField: 'params' // Replace with your metadata field
247
- }
248
- };
249
-
250
- await db.createCollection(collection_name, options); // Replace with your collection name
251
-
252
- return db.collection(collection_name);
253
-
254
- } catch (error) {
255
- console.error('Error connecting to MongoDB:', error);
256
-
257
- throw error;
258
- }
259
- }
260
-
261
- private getCollectionHandler(collection: string): any
262
- {
263
- if(!this.client || !this.connected){
264
- this.connectToDB();
265
- }
266
-
267
- return (this.client[collection as keyof PrismaClient] as any);
268
- }
269
-
270
- private setOpts(opts: IDBClientCreate = null): this
271
- {
272
- this.opts = opts;
273
- return this;
274
- }
275
- }
276
-
277
- export { DBService, IDBClientCreate };
1
+ import { PrismaClient } from '@prisma/client';
2
+ import { Collection, Db, MongoClient } from 'mongodb';
3
+ import {ITimeSeries} from '../types/ITimeSeries';
4
+ import { IModel } from '../models/interfaces/IModel';
5
+ import chalk from 'chalk';
6
+ import { IDbConfigHandler } from '../types/DbConfigHandler';
7
+ import { IPaginationParams } from '../types/FindParams';
8
+
9
+ interface IDBClientCreate {
10
+ dbUrl?: string;
11
+ dbName?: string;
12
+ }
13
+
14
+ class DBService {
15
+ private client: PrismaClient;
16
+ private opts: IDBClientCreate = null;
17
+ private connected = false;
18
+
19
+ constructor(private configService: IDbConfigHandler){}
20
+
21
+ private connectToDB(opts: IDBClientCreate = null) {
22
+ if(opts){
23
+ this.opts = opts;
24
+ }else{
25
+ this.opts = {
26
+ dbUrl: this.configService.get('db_url'),
27
+ dbName: this.configService.get('db_name'),
28
+ };
29
+ }
30
+
31
+ if(!this.opts.dbUrl){
32
+ console.log(chalk.red('No database config set in @rws-framework/db'));
33
+
34
+ return;
35
+ }
36
+
37
+ try{
38
+ this.client = new PrismaClient({
39
+ datasources: {
40
+ db: {
41
+ url: this.opts.dbUrl
42
+ },
43
+ },
44
+ });
45
+
46
+ this.connected = true;
47
+ } catch (e: Error | any){
48
+ console.error(e);
49
+
50
+ throw new Error('PRISMA CONNECTION ERROR');
51
+ }
52
+ }
53
+
54
+ reconnect(opts: IDBClientCreate = null)
55
+ {
56
+ this.connectToDB(opts);
57
+ }
58
+
59
+ static baseClientConstruct(dbUrl: string): MongoClient
60
+ {
61
+ const client = new MongoClient(dbUrl);
62
+
63
+ return client;
64
+ }
65
+
66
+ public async createBaseMongoClient(): Promise<MongoClient>
67
+ {
68
+ const dbUrl = this.opts?.dbUrl || this.configService.get('db_url');
69
+ const client = DBService.baseClientConstruct(dbUrl);
70
+
71
+ await client.connect();
72
+
73
+ return client;
74
+
75
+ }
76
+
77
+ public async createBaseMongoClientDB(): Promise<[MongoClient, Db]>
78
+ {
79
+ const dbName = this.opts?.dbName || this.configService.get('db_name');
80
+ const client = await this.createBaseMongoClient();
81
+ return [client, client.db(dbName)];
82
+ }
83
+
84
+ public async cloneDatabase(source: string, target: string): Promise<void> {
85
+ const client = await this.createBaseMongoClient();
86
+
87
+ // Source and target DB
88
+ const sourceDb = client.db(source);
89
+ const targetDb = client.db(target);
90
+
91
+ // Get all collections from source DB
92
+ const collections = await sourceDb.listCollections().toArray();
93
+
94
+ // Loop over all collections and copy them to the target DB
95
+ for (const collection of collections) {
96
+ const docs = await sourceDb.collection(collection.name).find({}).toArray();
97
+ await targetDb.collection(collection.name).insertMany(docs);
98
+ }
99
+
100
+ await client.close();
101
+ }
102
+
103
+ async watchCollection(collectionName: string, preRun: () => void): Promise<any>
104
+ {
105
+ const [client, db] = await this.createBaseMongoClientDB();
106
+ const collection = db.collection(collectionName);
107
+
108
+ const changeStream = collection.watch();
109
+ return new Promise((resolve) => {
110
+ changeStream.on('change', (change) => {
111
+ resolve(change);
112
+ });
113
+
114
+ preRun();
115
+ });
116
+ }
117
+
118
+ async insert(data: any, collection: string, isTimeSeries: boolean = false) {
119
+
120
+ let result: any = data;
121
+ // Insert time-series data outside of the transaction
122
+
123
+ if(isTimeSeries){
124
+ const [client, db] = await this.createBaseMongoClientDB();
125
+ const collectionHandler = db.collection(collection);
126
+
127
+ const insert = await collectionHandler.insertOne(data);
128
+
129
+ result = await this.findOneBy(collection, { id: insert.insertedId.toString() });
130
+ return result;
131
+ }
132
+
133
+ const prismaCollection = this.getCollectionHandler(collection);
134
+
135
+ result = await prismaCollection.create({ data });
136
+
137
+ return await this.findOneBy(collection, { id: result.id });
138
+ }
139
+
140
+ async update(data: any, collection: string): Promise<IModel>
141
+ {
142
+ const model_id: string = data.id;
143
+ delete data['id'];
144
+
145
+ const prismaCollection = this.getCollectionHandler(collection);
146
+
147
+ await prismaCollection.update({
148
+ where: {
149
+ id: model_id,
150
+ },
151
+ data: data,
152
+ });
153
+
154
+
155
+ return await this.findOneBy(collection, { id: model_id });
156
+ }
157
+
158
+
159
+ async findOneBy(collection: string, conditions: any, fields: string[] | null = null, ordering: { [fieldName: string]: string } = null, allowRelations: boolean = true): Promise<IModel|null>
160
+ {
161
+ const params: any = { where: conditions };
162
+
163
+ if(fields){
164
+ params.select = {};
165
+ fields.forEach((fieldName: string) => {
166
+ params.select[fieldName] = true;
167
+ });
168
+ }
169
+
170
+ if(ordering){
171
+ params.orderBy = ordering;
172
+ }
173
+
174
+ const retData = await this.getCollectionHandler(collection).findFirst(params);
175
+
176
+ return retData;
177
+ }
178
+
179
+ async delete(collection: string, conditions: any): Promise<void>
180
+ {
181
+ await this.getCollectionHandler(collection).deleteMany({ where: conditions });
182
+ return;
183
+ }
184
+
185
+ async findBy(
186
+ collection: string,
187
+ conditions: any,
188
+ fields: string[] | null = null,
189
+ ordering: { [fieldName: string]: string } = null,
190
+ pagination: IPaginationParams = null): Promise<IModel[]>
191
+ {
192
+ const params: any ={ where: conditions };
193
+
194
+ if(fields){
195
+ params.select = {};
196
+ fields.forEach((fieldName: string) => {
197
+ params.select[fieldName] = true;
198
+ });
199
+ }
200
+
201
+ if(ordering){
202
+ params.orderBy = ordering;
203
+ }
204
+
205
+ if(pagination){
206
+ const perPage = pagination.per_page || 50;
207
+ params.skip = (pagination.page || 0) * perPage;
208
+ params.take = perPage;
209
+ }
210
+
211
+ const retData = await this.getCollectionHandler(collection).findMany(params);
212
+
213
+ return retData;
214
+ }
215
+
216
+ async collectionExists(collection_name: string): Promise<boolean>
217
+ {
218
+ const dbUrl = this.opts?.dbUrl || this.configService.get('db_url');
219
+ const client = new MongoClient(dbUrl);
220
+
221
+ try {
222
+ await client.connect();
223
+
224
+ const db = client.db(this.configService.get('db_name'));
225
+
226
+ const collections = await db.listCollections().toArray();
227
+ const existingCollectionNames = collections.map((collection) => collection.name);
228
+
229
+ return existingCollectionNames.includes(collection_name);
230
+ } catch (error) {
231
+ console.error('Error connecting to MongoDB:', error);
232
+
233
+ throw error;
234
+ }
235
+ }
236
+
237
+ async createTimeSeriesCollection(collection_name: string): Promise<Collection<ITimeSeries>>
238
+ {
239
+ try {
240
+ const [client, db] = await this.createBaseMongoClientDB();
241
+
242
+ // Create a time series collection
243
+ const options = {
244
+ timeseries: {
245
+ timeField: 'timestamp', // Replace with your timestamp field
246
+ metaField: 'params' // Replace with your metadata field
247
+ }
248
+ };
249
+
250
+ await db.createCollection(collection_name, options); // Replace with your collection name
251
+
252
+ return db.collection(collection_name);
253
+
254
+ } catch (error) {
255
+ console.error('Error connecting to MongoDB:', error);
256
+
257
+ throw error;
258
+ }
259
+ }
260
+
261
+ private getCollectionHandler(collection: string): any
262
+ {
263
+ if(!this.client || !this.connected){
264
+ this.connectToDB();
265
+ }
266
+
267
+ return (this.client[collection as keyof PrismaClient] as any);
268
+ }
269
+
270
+ private setOpts(opts: IDBClientCreate = null): this
271
+ {
272
+ this.opts = opts;
273
+ return this;
274
+ }
275
+ }
276
+
277
+ export { DBService, IDBClientCreate };
@@ -1,11 +1,12 @@
1
- import { OpModelType } from "../models/interfaces/OpModelType";
2
-
3
- export interface IDbConfigParams {
4
- mongo_url?: string;
5
- mongo_db?: string;
6
- db_models?: OpModelType<any>[]
7
- }
8
-
9
- export interface IDbConfigHandler {
10
- get<K extends keyof IDbConfigParams>(key: K): IDbConfigParams[K];
11
- }
1
+ import { OpModelType } from "../models/interfaces/OpModelType";
2
+
3
+ export interface IDbConfigParams {
4
+ db_url?: string;
5
+ db_name?: string;
6
+ db_type?: string;
7
+ db_models?: OpModelType<any>[]
8
+ }
9
+
10
+ export interface IDbConfigHandler {
11
+ get<K extends keyof IDbConfigParams>(key: K): IDbConfigParams[K];
12
+ }