@reldens/storage 0.60.0 → 0.61.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/lib/base-data-server.js +13 -4
- package/lib/prisma/prisma-driver.js +31 -7
- package/package.json +4 -4
package/lib/base-data-server.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const { EntityManager } = require('./entity-manager');
|
|
8
|
-
const { ErrorManager, sc } = require('@reldens/utils');
|
|
8
|
+
const { ErrorManager, Logger, sc } = require('@reldens/utils');
|
|
9
9
|
|
|
10
10
|
class BaseDataServer
|
|
11
11
|
{
|
|
@@ -16,6 +16,9 @@ class BaseDataServer
|
|
|
16
16
|
if(!this.config.host){
|
|
17
17
|
this.config.host = 'localhost';
|
|
18
18
|
}
|
|
19
|
+
if(!this.config.port){
|
|
20
|
+
this.config.port = 3306;
|
|
21
|
+
}
|
|
19
22
|
this.client = sc.get(props, 'client', '');
|
|
20
23
|
this.poolConfig = sc.get(props, 'poolConfig', {});
|
|
21
24
|
this.connectStringOptions = sc.get(props, 'connectStringOptions', '');
|
|
@@ -33,11 +36,17 @@ class BaseDataServer
|
|
|
33
36
|
|
|
34
37
|
createConnectionString()
|
|
35
38
|
{
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
if('' === this.client){
|
|
40
|
+
Logger.warning('Client is empty, connection may fail.');
|
|
41
|
+
}
|
|
42
|
+
if('' === this.config.user){
|
|
43
|
+
Logger.warning('User is empty, connection may fail.');
|
|
44
|
+
}
|
|
45
|
+
return (this.client || '')+'://'
|
|
46
|
+
+(this.config.user || '')
|
|
38
47
|
+(this.config.password ? ':'+this.config.password : '')
|
|
39
48
|
+'@'+this.config.host
|
|
40
|
-
+':'+
|
|
49
|
+
+':'+this.config.port
|
|
41
50
|
+(this.config.database ? '/'+this.config.database : '')
|
|
42
51
|
+(this.connectStringOptions ? '?'+this.connectStringOptions : '');
|
|
43
52
|
}
|
|
@@ -38,7 +38,7 @@ class PrismaDriver extends BaseDriver
|
|
|
38
38
|
|
|
39
39
|
initModelMetadata()
|
|
40
40
|
{
|
|
41
|
-
let dmmf = this.
|
|
41
|
+
let dmmf = this.getDmmf();
|
|
42
42
|
if(!dmmf){
|
|
43
43
|
Logger.warning('Could not access Prisma DMMF metadata');
|
|
44
44
|
return;
|
|
@@ -61,6 +61,28 @@ class PrismaDriver extends BaseDriver
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
getDmmf()
|
|
65
|
+
{
|
|
66
|
+
try {
|
|
67
|
+
if(this.prisma._dmmf){
|
|
68
|
+
return this.prisma._dmmf.datamodel;
|
|
69
|
+
}
|
|
70
|
+
if(this.prisma._getDmmf && sc.isFunction(this.prisma._getDmmf)){
|
|
71
|
+
return this.prisma._getDmmf().datamodel;
|
|
72
|
+
}
|
|
73
|
+
if(this.prisma._runtimeDataModel){
|
|
74
|
+
return this.prisma._runtimeDataModel;
|
|
75
|
+
}
|
|
76
|
+
if(Prisma.dmmf && Prisma.dmmf.datamodel){
|
|
77
|
+
return Prisma.dmmf.datamodel;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
} catch(error) {
|
|
81
|
+
Logger.warning('Failed to access DMMF: '+error.message);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
64
86
|
processFieldMetadata(field)
|
|
65
87
|
{
|
|
66
88
|
this.fieldTypes[field.name] = field.type;
|
|
@@ -312,7 +334,7 @@ class PrismaDriver extends BaseDriver
|
|
|
312
334
|
|
|
313
335
|
tableName()
|
|
314
336
|
{
|
|
315
|
-
return this.model.name || '';
|
|
337
|
+
return this.model.$name || this.model.name || '';
|
|
316
338
|
}
|
|
317
339
|
|
|
318
340
|
property(propertyName)
|
|
@@ -337,7 +359,7 @@ class PrismaDriver extends BaseDriver
|
|
|
337
359
|
return data;
|
|
338
360
|
}
|
|
339
361
|
|
|
340
|
-
prepareDataWithRelations(params)
|
|
362
|
+
prepareDataWithRelations(params, isCreate = false)
|
|
341
363
|
{
|
|
342
364
|
let data = {};
|
|
343
365
|
let relations = {};
|
|
@@ -351,9 +373,11 @@ class PrismaDriver extends BaseDriver
|
|
|
351
373
|
};
|
|
352
374
|
continue;
|
|
353
375
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
376
|
+
if(!isCreate){
|
|
377
|
+
relations[relationName] = {
|
|
378
|
+
disconnect: true
|
|
379
|
+
};
|
|
380
|
+
}
|
|
357
381
|
continue;
|
|
358
382
|
}
|
|
359
383
|
let fieldType = this.fieldTypes[key];
|
|
@@ -476,7 +500,7 @@ class PrismaDriver extends BaseDriver
|
|
|
476
500
|
|
|
477
501
|
async create(params)
|
|
478
502
|
{
|
|
479
|
-
let preparedData = this.prepareDataWithRelations(params);
|
|
503
|
+
let preparedData = this.prepareDataWithRelations(params, true);
|
|
480
504
|
this.ensureRequiredFields(preparedData);
|
|
481
505
|
try {
|
|
482
506
|
return await this.model.create({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reldens/storage",
|
|
3
3
|
"scope": "@reldens",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.61.0",
|
|
5
5
|
"description": "Reldens - Storage",
|
|
6
6
|
"author": "Damian A. Pastorini",
|
|
7
7
|
"license": "MIT",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"@mikro-orm/core": "^6.4.16",
|
|
46
46
|
"@mikro-orm/mongodb": "^6.4.16",
|
|
47
47
|
"@mikro-orm/mysql": "^6.4.16",
|
|
48
|
-
"@prisma/client": "^6.
|
|
49
|
-
"@reldens/server-utils": "^0.
|
|
48
|
+
"@prisma/client": "^6.11.0",
|
|
49
|
+
"@reldens/server-utils": "^0.21.0",
|
|
50
50
|
"@reldens/utils": "^0.50.0",
|
|
51
51
|
"knex": "^3.1.0",
|
|
52
52
|
"mysql": "^2.18.1",
|
|
53
53
|
"mysql2": "^3.14.1",
|
|
54
54
|
"objection": "^3.1.5",
|
|
55
|
-
"prisma": "^6.
|
|
55
|
+
"prisma": "^6.11.0"
|
|
56
56
|
}
|
|
57
57
|
}
|