@cheetah.js/orm 0.1.95 → 0.1.97
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/dist/SqlBuilder.d.ts +6 -0
- package/dist/SqlBuilder.js +41 -1
- package/package.json +2 -2
package/dist/SqlBuilder.d.ts
CHANGED
|
@@ -55,6 +55,12 @@ export declare class SqlBuilder<T> {
|
|
|
55
55
|
private objectToStringMap;
|
|
56
56
|
private mapObjectKey;
|
|
57
57
|
private isNestedObject;
|
|
58
|
+
private buildColumnPath;
|
|
59
|
+
private splitPath;
|
|
60
|
+
private resolvePathEntity;
|
|
61
|
+
private nextEntity;
|
|
62
|
+
private resolveColumn;
|
|
63
|
+
private joinSegments;
|
|
58
64
|
private getTableName;
|
|
59
65
|
private t;
|
|
60
66
|
private getEntity;
|
package/dist/SqlBuilder.js
CHANGED
|
@@ -310,7 +310,8 @@ class SqlBuilder {
|
|
|
310
310
|
return this.objectToStringMap(obj[key], fullKey);
|
|
311
311
|
}
|
|
312
312
|
if (parentKey) {
|
|
313
|
-
|
|
313
|
+
const columnPath = this.buildColumnPath(fullKey);
|
|
314
|
+
return [`${this.columnManager.discoverAlias(columnPath, true)} ${obj[key]}`];
|
|
314
315
|
}
|
|
315
316
|
const columnName = value_processor_1.ValueProcessor.getColumnName(key, this.entity);
|
|
316
317
|
return [`${this.columnManager.discoverAlias(columnName, true)} ${obj[key]}`];
|
|
@@ -318,6 +319,45 @@ class SqlBuilder {
|
|
|
318
319
|
isNestedObject(value) {
|
|
319
320
|
return typeof value === 'object' && value !== null;
|
|
320
321
|
}
|
|
322
|
+
buildColumnPath(path) {
|
|
323
|
+
const segments = this.splitPath(path);
|
|
324
|
+
const entity = this.resolvePathEntity(segments.parents);
|
|
325
|
+
const column = this.resolveColumn(segments.column, entity);
|
|
326
|
+
return this.joinSegments(segments.parents, column);
|
|
327
|
+
}
|
|
328
|
+
splitPath(path) {
|
|
329
|
+
const parts = path.split('.');
|
|
330
|
+
const column = parts.pop() ?? path;
|
|
331
|
+
return { parents: parts, column };
|
|
332
|
+
}
|
|
333
|
+
resolvePathEntity(parents) {
|
|
334
|
+
let current = this.entity;
|
|
335
|
+
for (const relation of parents) {
|
|
336
|
+
current = this.nextEntity(current, relation);
|
|
337
|
+
}
|
|
338
|
+
return current;
|
|
339
|
+
}
|
|
340
|
+
nextEntity(entity, relation) {
|
|
341
|
+
const relations = entity.relations ?? [];
|
|
342
|
+
const meta = relations.find(rel => rel.propertyKey === relation);
|
|
343
|
+
if (!meta) {
|
|
344
|
+
throw new Error(`Relationship "${relation}" not found for ORDER BY path`);
|
|
345
|
+
}
|
|
346
|
+
const next = this.entityStorage.get(meta.entity());
|
|
347
|
+
if (!next) {
|
|
348
|
+
throw new Error(`Entity metadata not found for relation "${relation}"`);
|
|
349
|
+
}
|
|
350
|
+
return next;
|
|
351
|
+
}
|
|
352
|
+
resolveColumn(column, entity) {
|
|
353
|
+
return value_processor_1.ValueProcessor.getColumnName(column, entity);
|
|
354
|
+
}
|
|
355
|
+
joinSegments(parents, column) {
|
|
356
|
+
if (parents.length === 0) {
|
|
357
|
+
return column;
|
|
358
|
+
}
|
|
359
|
+
return `${parents.join('.')}.${column}`;
|
|
360
|
+
}
|
|
321
361
|
getTableName() {
|
|
322
362
|
const tableName = this.entity.tableName || this.model.name.toLowerCase();
|
|
323
363
|
const schema = this.entity.schema || 'public';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cheetah.js/orm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.97",
|
|
4
4
|
"description": "A simple ORM for Cheetah.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"bun",
|
|
56
56
|
"value-object"
|
|
57
57
|
],
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "48d918882673a3223e28961d90d2ff54b0f80565"
|
|
59
59
|
}
|