@reldens/storage 0.85.0 → 0.87.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/CLAUDE.md +78 -18
- package/README.md +52 -21
- package/bin/reldens-storage.js +4 -25
- package/index.js +2 -0
- package/lib/prisma/prisma-client-loader.js +41 -0
- package/package.json +7 -7
package/CLAUDE.md
CHANGED
|
@@ -111,6 +111,7 @@ npx reldens-storage-prisma --host=<host> --database=<db> --user=<user> --passwor
|
|
|
111
111
|
- `prisma-metadata-loader.js`: Loads field metadata including defaults
|
|
112
112
|
- `prisma-type-caster.js`: Type casting and normalization
|
|
113
113
|
- `prisma-relation-resolver.js`: Relation mapping and transformations
|
|
114
|
+
- `prisma-client-loader.js`: Utility for loading Prisma Client instances
|
|
114
115
|
- Features:
|
|
115
116
|
- Schema-first approach with auto-introspection
|
|
116
117
|
- Type-safe queries with Prisma Client
|
|
@@ -212,24 +213,22 @@ Templates use placeholder replacement with `{{placeholderName}}` syntax.
|
|
|
212
213
|
|
|
213
214
|
## Generated File Structure
|
|
214
215
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
└── entities-translations.js # Translation keys
|
|
232
|
-
```
|
|
216
|
+
All generated files are created in the **generated-entities/** directory:
|
|
217
|
+
|
|
218
|
+
**Entity Definitions:**
|
|
219
|
+
- entities/[table-name]-entity.js
|
|
220
|
+
|
|
221
|
+
**Driver Models:**
|
|
222
|
+
- models/objection-js/[table-name]-model.js
|
|
223
|
+
- models/objection-js/registered-models-objection-js.js
|
|
224
|
+
- models/mikro-orm/[table-name]-model.js
|
|
225
|
+
- models/mikro-orm/registered-models-mikro-orm.js
|
|
226
|
+
- models/prisma/[table-name]-model.js
|
|
227
|
+
- models/prisma/registered-models-prisma.js
|
|
228
|
+
|
|
229
|
+
**Configuration Files:**
|
|
230
|
+
- entities-config.js (entity relation configuration)
|
|
231
|
+
- entities-translations.js (translation keys)
|
|
233
232
|
|
|
234
233
|
## Relation Keys Pattern
|
|
235
234
|
|
|
@@ -398,3 +397,64 @@ The `prepareDataWithRelations()` method (lines 156-199) automatically converts F
|
|
|
398
397
|
- `RELDENS_DB_PARAMS`: Database connection parameters (used by Prisma)
|
|
399
398
|
- Format: `key1=value1&key2=value2`
|
|
400
399
|
- Example: `authPlugin=mysql_native_password&sslmode=require`
|
|
400
|
+
|
|
401
|
+
## PrismaClientLoader Utility
|
|
402
|
+
|
|
403
|
+
**Location:** `lib/prisma/prisma-client-loader.js`
|
|
404
|
+
|
|
405
|
+
**Purpose:** Shared utility for loading Prisma Client instances in CLI tools and applications.
|
|
406
|
+
|
|
407
|
+
**Exported From Package:** Yes, available via `const { PrismaClientLoader } = require('@reldens/storage');`
|
|
408
|
+
|
|
409
|
+
**Method:**
|
|
410
|
+
```javascript
|
|
411
|
+
PrismaClientLoader.load(projectPath, customPath, connectionData)
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
**Parameters:**
|
|
415
|
+
- `projectPath` (string): Project root directory path
|
|
416
|
+
- `customPath` (string|null): Optional custom path to Prisma client (overrides default)
|
|
417
|
+
- `connectionData` (object): Database connection configuration with properties:
|
|
418
|
+
- `client` (string): Database client type (mysql, postgresql, etc.)
|
|
419
|
+
- `user` (string): Database username
|
|
420
|
+
- `password` (string): Database password
|
|
421
|
+
- `host` (string): Database host
|
|
422
|
+
- `port` (number): Database port
|
|
423
|
+
- `database` (string): Database name
|
|
424
|
+
|
|
425
|
+
**Returns:** PrismaClient instance or null on error
|
|
426
|
+
|
|
427
|
+
**Behavior:**
|
|
428
|
+
- If `customPath` is provided, uses that path
|
|
429
|
+
- Otherwise uses default path: `projectPath/prisma/client`
|
|
430
|
+
- Validates that Prisma Client exists at the path
|
|
431
|
+
- Requires `prismaModule.PrismaClient` export
|
|
432
|
+
- Builds connection string from connectionData
|
|
433
|
+
- Returns initialized PrismaClient with connection configuration
|
|
434
|
+
|
|
435
|
+
**Usage Example:**
|
|
436
|
+
```javascript
|
|
437
|
+
const { PrismaClientLoader } = require('@reldens/storage');
|
|
438
|
+
|
|
439
|
+
const prismaClient = PrismaClientLoader.load(
|
|
440
|
+
process.cwd(),
|
|
441
|
+
null,
|
|
442
|
+
{
|
|
443
|
+
client: 'mysql',
|
|
444
|
+
user: 'dbuser',
|
|
445
|
+
password: 'dbpass',
|
|
446
|
+
host: 'localhost',
|
|
447
|
+
port: 3306,
|
|
448
|
+
database: 'mydb'
|
|
449
|
+
}
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
if(!prismaClient){
|
|
453
|
+
console.error('Failed to load Prisma client');
|
|
454
|
+
process.exit(1);
|
|
455
|
+
}
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
**Used By:**
|
|
459
|
+
- `bin/reldens-storage.js`: CLI entity generator
|
|
460
|
+
- External packages: `@reldens/cms` CLI tools (update-password, generate-entities, generate-sitemap)
|
package/README.md
CHANGED
|
@@ -182,6 +182,37 @@ const entities = server.generateEntities();
|
|
|
182
182
|
|
|
183
183
|
Note: The PrismaDataServer requires the Prisma schema to be generated first. Make sure to run the `reldens-generate-prisma-schema` command before using PrismaDataServer.
|
|
184
184
|
|
|
185
|
+
### Loading Prisma Client Programmatically
|
|
186
|
+
|
|
187
|
+
If you need to load a Prisma Client instance in your CLI tools or applications:
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
const { PrismaClientLoader } = require('@reldens/storage');
|
|
191
|
+
|
|
192
|
+
const prismaClient = PrismaClientLoader.load(
|
|
193
|
+
process.cwd(),
|
|
194
|
+
null,
|
|
195
|
+
{
|
|
196
|
+
client: 'mysql',
|
|
197
|
+
user: 'dbuser',
|
|
198
|
+
password: 'dbpass',
|
|
199
|
+
host: 'localhost',
|
|
200
|
+
port: 3306,
|
|
201
|
+
database: 'mydb'
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
if(!prismaClient){
|
|
206
|
+
console.error('Failed to load Prisma client');
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Parameters:
|
|
212
|
+
- `projectPath`: Project root directory
|
|
213
|
+
- `customPath`: Optional custom path to Prisma client (null for default)
|
|
214
|
+
- `connectionData`: Database connection configuration object
|
|
215
|
+
|
|
185
216
|
## Custom Drivers
|
|
186
217
|
|
|
187
218
|
You can create custom storage drivers by extending the base classes:
|
|
@@ -237,28 +268,28 @@ All drivers must implement the methods defined in `BaseDriver`:
|
|
|
237
268
|
|
|
238
269
|
## Generated File Structure
|
|
239
270
|
|
|
240
|
-
When you run entity generation, files are created in the
|
|
271
|
+
When you run entity generation, all files are created in the **generated-entities/** directory:
|
|
241
272
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
273
|
+
**Entity Definitions:**
|
|
274
|
+
- entities/users-entity.js
|
|
275
|
+
- entities/players-entity.js
|
|
276
|
+
|
|
277
|
+
**ObjectionJS Models:**
|
|
278
|
+
- models/objection-js/users-model.js
|
|
279
|
+
- models/objection-js/players-model.js
|
|
280
|
+
- models/objection-js/registered-models-objection-js.js
|
|
281
|
+
|
|
282
|
+
**MikroORM Models:**
|
|
283
|
+
- models/mikro-orm/users-model.js
|
|
284
|
+
- models/mikro-orm/registered-models-mikro-orm.js
|
|
285
|
+
|
|
286
|
+
**Prisma Models:**
|
|
287
|
+
- models/prisma/users-model.js
|
|
288
|
+
- models/prisma/registered-models-prisma.js
|
|
289
|
+
|
|
290
|
+
**Configuration Files:**
|
|
291
|
+
- entities-config.js (entity relations)
|
|
292
|
+
- entities-translations.js (i18n keys)
|
|
262
293
|
|
|
263
294
|
### Entity Files
|
|
264
295
|
- **Entity classes**: Define properties, types, validations
|
package/bin/reldens-storage.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
const { EntitiesGenerator } = require('../lib/entities-generator');
|
|
10
|
-
const {
|
|
10
|
+
const { PrismaClientLoader } = require('../lib/prisma/prisma-client-loader');
|
|
11
11
|
const { Logger, sc } = require('@reldens/utils');
|
|
12
12
|
|
|
13
13
|
class StorageEntitiesGenerator
|
|
@@ -113,32 +113,11 @@ class StorageEntitiesGenerator
|
|
|
113
113
|
|
|
114
114
|
loadPrismaClient(connectionData)
|
|
115
115
|
{
|
|
116
|
-
let
|
|
117
|
-
if(!
|
|
118
|
-
prismaClientPath = FileHandler.joinPaths(this.projectPath, 'prisma', 'client');
|
|
119
|
-
}
|
|
120
|
-
if(!FileHandler.exists(prismaClientPath)){
|
|
121
|
-
Logger.critical('PrismaClient path does not exist: '+prismaClientPath);
|
|
116
|
+
let loadedClient = PrismaClientLoader.load(this.projectPath, this.prismaClientPath, connectionData);
|
|
117
|
+
if(!loadedClient){
|
|
122
118
|
Logger.info('Please run "npx prisma generate" first or provide --prismaClientPath argument.');
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
Logger.info('Loading PrismaClient from: '+prismaClientPath);
|
|
126
|
-
let prismaModule = require(prismaClientPath);
|
|
127
|
-
if(!prismaModule.PrismaClient){
|
|
128
|
-
Logger.critical('PrismaClient class not found at: '+prismaClientPath);
|
|
129
|
-
return null;
|
|
130
119
|
}
|
|
131
|
-
|
|
132
|
-
+connectionData.user
|
|
133
|
-
+(connectionData.password ? ':'+connectionData.password : '')
|
|
134
|
-
+'@'+connectionData.host
|
|
135
|
-
+':'+connectionData.port
|
|
136
|
-
+'/'+connectionData.database;
|
|
137
|
-
Logger.info('Creating PrismaClient with connection to: '+connectionData.database);
|
|
138
|
-
return new prismaModule.PrismaClient({
|
|
139
|
-
datasources: {db: {url: connectionString}},
|
|
140
|
-
log: ['error']
|
|
141
|
-
});
|
|
120
|
+
return loadedClient;
|
|
142
121
|
}
|
|
143
122
|
|
|
144
123
|
async run()
|
package/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const { MySQLTablesProvider } = require('./lib/mysql-tables-provider');
|
|
|
19
19
|
const { PrismaDriver } = require('./lib/prisma/prisma-driver');
|
|
20
20
|
const { PrismaDataServer } = require('./lib/prisma/prisma-data-server');
|
|
21
21
|
const { PrismaSchemaGenerator } = require('./lib/prisma/prisma-schema-generator');
|
|
22
|
+
const { PrismaClientLoader } = require('./lib/prisma/prisma-client-loader');
|
|
22
23
|
|
|
23
24
|
module.exports = {
|
|
24
25
|
// base:
|
|
@@ -46,6 +47,7 @@ module.exports = {
|
|
|
46
47
|
PrismaDataServer,
|
|
47
48
|
PrismaDriver,
|
|
48
49
|
PrismaSchemaGenerator,
|
|
50
|
+
PrismaClientLoader,
|
|
49
51
|
// entities:
|
|
50
52
|
EntitiesGenerator,
|
|
51
53
|
EntityProperties,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Storage - PrismaClientLoader
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { Logger } = require('@reldens/utils');
|
|
8
|
+
const { FileHandler } = require('@reldens/server-utils');
|
|
9
|
+
|
|
10
|
+
class PrismaClientLoader
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
static load(projectPath, customPath, connectionData)
|
|
14
|
+
{
|
|
15
|
+
let prismaClientPath = customPath;
|
|
16
|
+
if(!prismaClientPath){
|
|
17
|
+
prismaClientPath = FileHandler.joinPaths(projectPath, 'prisma', 'client');
|
|
18
|
+
}
|
|
19
|
+
if(!FileHandler.exists(prismaClientPath)){
|
|
20
|
+
Logger.critical('PrismaClient path does not exist: '+prismaClientPath);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
Logger.info('Loading PrismaClient from: '+prismaClientPath);
|
|
24
|
+
let prismaModule = require(prismaClientPath);
|
|
25
|
+
if(!prismaModule.PrismaClient){
|
|
26
|
+
Logger.critical('PrismaClient class not found at: '+prismaClientPath);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
let connectionString = connectionData.client+'://'
|
|
30
|
+
+connectionData.user
|
|
31
|
+
+(connectionData.password ? ':'+connectionData.password : '')
|
|
32
|
+
+'@'+connectionData.host
|
|
33
|
+
+':'+connectionData.port
|
|
34
|
+
+'/'+connectionData.database;
|
|
35
|
+
Logger.info('Creating PrismaClient with connection to: '+connectionData.database);
|
|
36
|
+
return new prismaModule.PrismaClient({datasources: {db: {url: connectionString}}, log: ['error']});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports.PrismaClientLoader = PrismaClientLoader;
|
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.87.0",
|
|
5
5
|
"description": "Reldens - Storage",
|
|
6
6
|
"author": "Damian A. Pastorini",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
"url": "https://github.com/damian-pastorini/reldens-storage/issues"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@mikro-orm/core": "6.6.
|
|
46
|
-
"@mikro-orm/mongodb": "6.6.
|
|
47
|
-
"@mikro-orm/mysql": "6.6.
|
|
48
|
-
"@prisma/client": "6.19.
|
|
49
|
-
"@reldens/server-utils": "^0.
|
|
45
|
+
"@mikro-orm/core": "6.6.4",
|
|
46
|
+
"@mikro-orm/mongodb": "6.6.4",
|
|
47
|
+
"@mikro-orm/mysql": "6.6.4",
|
|
48
|
+
"@prisma/client": "6.19.2",
|
|
49
|
+
"@reldens/server-utils": "^0.44.0",
|
|
50
50
|
"@reldens/utils": "^0.54.0",
|
|
51
51
|
"knex": "3.1.0",
|
|
52
52
|
"mysql": "2.18.1",
|
|
53
53
|
"mysql2": "3.16.0",
|
|
54
54
|
"objection": "3.1.5",
|
|
55
|
-
"prisma": "6.19.
|
|
55
|
+
"prisma": "6.19.2"
|
|
56
56
|
}
|
|
57
57
|
}
|