@cheetah.js/orm 0.1.97 → 0.1.99

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.
@@ -22,4 +22,7 @@ export declare class SqlColumnManager {
22
22
  private buildJoinMaps;
23
23
  private findNextAlias;
24
24
  private formatColumnWithAlias;
25
+ private getColumnNameFromProperty;
26
+ private getColumnNameFromPropertyForEntity;
27
+ private getEntityFromAlias;
25
28
  }
@@ -65,10 +65,11 @@ class SqlColumnManager {
65
65
  return column.includes('.');
66
66
  }
67
67
  buildSimpleColumnAlias(column, alias, onlyAlias) {
68
+ const columnName = this.getColumnNameFromProperty(column);
68
69
  if (onlyAlias) {
69
- return `${alias}."${column}"`;
70
+ return `${alias}."${columnName}"`;
70
71
  }
71
- return `${alias}."${column}" as ${alias}_${column}`;
72
+ return `${alias}."${columnName}" as ${alias}_${columnName}`;
72
73
  }
73
74
  buildNestedColumnAlias(column, onlyAlias) {
74
75
  this.validateJoinsExist();
@@ -118,11 +119,39 @@ class SqlColumnManager {
118
119
  }
119
120
  return null;
120
121
  }
121
- formatColumnWithAlias(alias, columnName, onlyAlias) {
122
+ formatColumnWithAlias(alias, propertyName, onlyAlias) {
123
+ const entity = this.getEntityFromAlias(alias);
124
+ const columnName = this.getColumnNameFromPropertyForEntity(propertyName, entity);
122
125
  if (onlyAlias) {
123
126
  return `${alias}."${columnName}"`;
124
127
  }
125
128
  return `${alias}."${columnName}" as ${alias}_${columnName}`;
126
129
  }
130
+ getColumnNameFromProperty(propertyName) {
131
+ return this.getColumnNameFromPropertyForEntity(propertyName, this.entity);
132
+ }
133
+ getColumnNameFromPropertyForEntity(propertyName, entity) {
134
+ if (entity.properties[propertyName]) {
135
+ return entity.properties[propertyName].options.columnName;
136
+ }
137
+ const relation = entity.relations?.find(rel => rel.propertyKey === propertyName);
138
+ if (relation) {
139
+ return relation.columnName;
140
+ }
141
+ return propertyName;
142
+ }
143
+ getEntityFromAlias(alias) {
144
+ if (alias === this.statements.alias) {
145
+ return this.entity;
146
+ }
147
+ const join = this.statements.join?.find(j => j.joinAlias === alias);
148
+ if (join?.joinEntity) {
149
+ const entity = this.entityStorage.get(join.joinEntity);
150
+ if (entity) {
151
+ return entity;
152
+ }
153
+ }
154
+ return this.entity;
155
+ }
127
156
  }
128
157
  exports.SqlColumnManager = SqlColumnManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cheetah.js/orm",
3
- "version": "0.1.97",
3
+ "version": "0.1.99",
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": "48d918882673a3223e28961d90d2ff54b0f80565"
58
+ "gitHead": "c49400c65f80efbefc86cedf0beaf1eaf5fcdc03"
59
59
  }