@reldens/storage 0.55.0 → 0.56.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.
|
@@ -48,6 +48,7 @@ class EntitiesGenerator
|
|
|
48
48
|
this.server = sc.get(props, 'server', false);
|
|
49
49
|
this.connectionData = sc.get(props, 'connectionData', false);
|
|
50
50
|
this.isOverride = sc.get(props, 'isOverride', false);
|
|
51
|
+
this.prismaClient = sc.get(props, 'prismaClient', false);
|
|
51
52
|
this.generatedEntities = {};
|
|
52
53
|
this.existingEntities = {};
|
|
53
54
|
this.existingEntityFields = {};
|
|
@@ -327,7 +328,7 @@ class EntitiesGenerator
|
|
|
327
328
|
Logger.critical('Unsupported driver: '+driverKey);
|
|
328
329
|
return false;
|
|
329
330
|
}
|
|
330
|
-
|
|
331
|
+
let serverConfig = {
|
|
331
332
|
client: sc.get(this.connectionData, 'client', 'mysql2'),
|
|
332
333
|
config: {
|
|
333
334
|
user: sc.get(this.connectionData, 'user', ''),
|
|
@@ -336,7 +337,11 @@ class EntitiesGenerator
|
|
|
336
337
|
host: sc.get(this.connectionData, 'host', 'localhost'),
|
|
337
338
|
port: sc.get(this.connectionData, 'port', 3306)
|
|
338
339
|
}
|
|
339
|
-
}
|
|
340
|
+
};
|
|
341
|
+
if('prisma' === driverKey && this.prismaClient){
|
|
342
|
+
serverConfig.prismaClient = this.prismaClient;
|
|
343
|
+
}
|
|
344
|
+
this.server = new driverClassMapped(serverConfig);
|
|
340
345
|
return this.server;
|
|
341
346
|
}
|
|
342
347
|
|
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const { PrismaClient } = require('@prisma/client');
|
|
8
|
-
|
|
9
7
|
class {{modelClassName}}
|
|
10
8
|
{
|
|
11
9
|
|
|
@@ -14,19 +12,6 @@ class {{modelClassName}}
|
|
|
14
12
|
{{modelPropertiesConstructor}}
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
static get client()
|
|
18
|
-
{
|
|
19
|
-
if(!this._client){
|
|
20
|
-
this._client = new PrismaClient();
|
|
21
|
-
}
|
|
22
|
-
return this._client;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static get model()
|
|
26
|
-
{
|
|
27
|
-
return this.client['{{tableName}}'];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
15
|
static get tableName()
|
|
31
16
|
{
|
|
32
17
|
return '{{tableName}}';
|
|
@@ -15,7 +15,7 @@ class MySQLTablesProvider
|
|
|
15
15
|
' TABLE_NAME, ' +
|
|
16
16
|
' COLUMN_NAME, ' +
|
|
17
17
|
' DATA_TYPE, ' +
|
|
18
|
-
' CHARACTER_MAXIMUM_LENGTH, ' +
|
|
18
|
+
' CAST(CHARACTER_MAXIMUM_LENGTH AS CHAR) as CHARACTER_MAXIMUM_LENGTH, ' +
|
|
19
19
|
' COLUMN_TYPE, ' +
|
|
20
20
|
' IS_NULLABLE, ' +
|
|
21
21
|
' COLUMN_KEY, ' +
|
|
@@ -8,7 +8,7 @@ const { BaseDataServer } = require('../base-data-server');
|
|
|
8
8
|
const { PrismaDriver } = require('./prisma-driver');
|
|
9
9
|
const { MySQLTablesProvider } = require('../mysql-tables-provider');
|
|
10
10
|
const { PrismaClient } = require('@prisma/client');
|
|
11
|
-
const { Logger } = require('@reldens/utils');
|
|
11
|
+
const { Logger, sc } = require('@reldens/utils');
|
|
12
12
|
|
|
13
13
|
class PrismaDataServer extends BaseDataServer
|
|
14
14
|
{
|
|
@@ -16,7 +16,7 @@ class PrismaDataServer extends BaseDataServer
|
|
|
16
16
|
constructor(props)
|
|
17
17
|
{
|
|
18
18
|
super(props);
|
|
19
|
-
this.prisma = false;
|
|
19
|
+
this.prisma = sc.get(props, 'prismaClient', false);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
async connect()
|
|
@@ -25,10 +25,15 @@ class PrismaDataServer extends BaseDataServer
|
|
|
25
25
|
return this.initialized;
|
|
26
26
|
}
|
|
27
27
|
try {
|
|
28
|
-
this.prisma
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
if(!this.prisma){
|
|
29
|
+
this.prisma = new PrismaClient({
|
|
30
|
+
datasources: {db: {url: this.connectString}},
|
|
31
|
+
log: this.debug ? ['query', 'info', 'warn', 'error'] : ['error']
|
|
32
|
+
});
|
|
33
|
+
}
|
|
31
34
|
await this.prisma.$connect();
|
|
35
|
+
let dbTest = await this.prisma.$queryRaw`SELECT DATABASE() as current_db`;
|
|
36
|
+
Logger.info('Connected to database: ' + dbTest[0].current_db);
|
|
32
37
|
this.initialized = Date.now();
|
|
33
38
|
return this.initialized;
|
|
34
39
|
} catch(error) {
|
|
@@ -86,7 +91,9 @@ class PrismaDataServer extends BaseDataServer
|
|
|
86
91
|
continue;
|
|
87
92
|
}
|
|
88
93
|
try {
|
|
89
|
-
|
|
94
|
+
let result = await this.executeStatement(cleanStatement);
|
|
95
|
+
results.push(result);
|
|
96
|
+
Logger.debug('Statement executed, result: ' + JSON.stringify(result));
|
|
90
97
|
} catch(stmtError) {
|
|
91
98
|
Logger.error('Statement "'+cleanStatement+'" execution failed: '+stmtError.message);
|
|
92
99
|
return false;
|
|
@@ -109,7 +116,11 @@ class PrismaDataServer extends BaseDataServer
|
|
|
109
116
|
if(trimmedStatement.startsWith('SELECT')){
|
|
110
117
|
return await this.prisma.$queryRawUnsafe(statement);
|
|
111
118
|
}
|
|
119
|
+
if(trimmedStatement.startsWith('SHOW')){
|
|
120
|
+
return await this.prisma.$queryRawUnsafe(statement);
|
|
121
|
+
}
|
|
112
122
|
let result = await this.prisma.$executeRawUnsafe(statement);
|
|
123
|
+
Logger.debug('Raw result from Prisma: ' + result);
|
|
113
124
|
if(
|
|
114
125
|
trimmedStatement.startsWith('CREATE')
|
|
115
126
|
|| trimmedStatement.startsWith('ALTER')
|