@zuzjs/orm 0.3.5 → 0.3.6

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.
@@ -163,13 +163,15 @@ class MySqlDriver {
163
163
  for (const fk of fks) {
164
164
  const targetTable = fk.REFERENCED_TABLE_NAME;
165
165
  const fkColumn = fk.COLUMN_NAME;
166
+ const fkPropName = `fk${(0, index_js_1.toPascalCase)(targetTable)}`;
166
167
  if (!inverseRelations[targetTable]) {
167
168
  inverseRelations[targetTable] = [];
168
169
  }
169
170
  inverseRelations[targetTable].push({
170
171
  fkColumn,
172
+ fkPropName,
171
173
  targetTable: tableName,
172
- targetEntity: (0, index_js_1.toPascalCase)(tableName)
174
+ targetEntity: (0, index_js_1.toPascalCase)(tableName),
173
175
  });
174
176
  }
175
177
  }
@@ -269,17 +271,18 @@ class MySqlDriver {
269
271
  const inverse = inverseRelations[String(tableName)] || [];
270
272
  for (const rel of inverse) {
271
273
  const propName = rel.targetTable.endsWith('s') ? rel.targetTable : `${rel.targetTable}s`;
272
- // Avoid duplicate
273
- if (entityCode.some(line => line.includes(`@${propName}`)))
274
+ if (entityCode.some(line => line.includes(` ${propName}!:`)))
274
275
  continue;
275
276
  const importLine = `import { ${rel.targetEntity} } from "./${rel.targetTable}";`;
276
- if (!imports.includes(importLine)) {
277
+ if (!imports.includes(importLine))
277
278
  imports.push(importLine);
278
- }
279
279
  if (!_imports.includes('OneToMany'))
280
280
  _imports.push('OneToMany');
281
- entityCode.push(`\t@OneToMany(() => ${rel.targetEntity}, r => r.${rel.fkColumn})`);
281
+ // CORRECT: Inverse is fk + referenced table (e.g. fkUsers)
282
+ entityCode.push(`\t@OneToMany(() => ${rel.targetEntity}, r => r.${rel.fkPropName})`);
282
283
  entityCode.push(`\tfk${(0, index_js_1.toPascalCase)(propName)}!: ${rel.targetEntity}[];\n`);
284
+ // entityCode.push(`\t@OneToMany(() => ${targetEntity}, r => r.${rel.fkColumn})`);
285
+ // entityCode.push(`\tfk${toPascalCase(propName)}!: ${targetEntity}[];\n`);
283
286
  }
284
287
  // Add Many-to-Many Relations
285
288
  const junctions = Object.values(junctionTables)
@@ -321,6 +324,11 @@ class MySqlDriver {
321
324
  // Write entity file
322
325
  fs_1.default.writeFileSync(path_1.default.join(this.dist, `${tableName}.ts`), Code.join(`\n`));
323
326
  }
327
+ // Write entry file i.e index.ts
328
+ const entry = tableNames
329
+ .map(tableName => `import { ${(0, index_js_1.toPascalCase)(tableName)} } from "./${tableName}";`);
330
+ entry.push(`import Zorm from "@zuzjs/orm";`, `import de from "dotenv";`, `de.config()`, `const zorm = Zorm.get(process.env.DATABASE_URL!);`, `zorm.connect([${tableNames.map(t => (0, index_js_1.toPascalCase)(t)).join(`, `)}]);`, `export default zorm`, `export { ${tableNames.map(t => (0, index_js_1.toPascalCase)(t)).join(`, `)} }`);
331
+ fs_1.default.writeFileSync(path_1.default.join(this.dist, `index.ts`), entry.join(`\n`));
324
332
  await self.pool.end();
325
333
  console.log(picocolors_1.default.green(`✓ ${tables.length} Tables Processed.`));
326
334
  }
@@ -13,6 +13,7 @@ declare class ZormQueryBuilder<T extends ObjectLiteral, R = QueryResult> extends
13
13
  private whereCount;
14
14
  private isActiveRecord;
15
15
  private activeRecord;
16
+ private joinedAliases;
16
17
  constructor(repository: Repository<T>, _action: QueryAction, _usePromise?: boolean);
17
18
  _create(): this;
18
19
  upsert(): this;
@@ -16,6 +16,8 @@ class ZormQueryBuilder extends Promise {
16
16
  whereCount = 0;
17
17
  isActiveRecord = false;
18
18
  activeRecord;
19
+ joinedAliases = {};
20
+ // private currentWhereLogic: 'AND' | 'OR' = 'AND';
19
21
  constructor(repository, _action, _usePromise) {
20
22
  super(() => { }); // Required for extending Promise
21
23
  this.repository = repository;
@@ -146,7 +148,7 @@ class ZormQueryBuilder extends Promise {
146
148
  const match = value.match(/^(!=|>=|<=|>|<|=)\s*(.+)$/); // Improved regex
147
149
  if (match) {
148
150
  const [, operator, rawValue] = match;
149
- const sqlOperator = operator; // Directly use the matched operator
151
+ sqlOperator = operator; // Directly use the matched operator
150
152
  const parsedValue = !isNaN(Number(rawValue)) ? Number(rawValue) : rawValue.trim(); // Convert to number if possible
151
153
  qb[type](`${qb.alias}.${key} ${sqlOperator} :${paramKey}`, { [paramKey]: parsedValue });
152
154
  return;
@@ -273,6 +275,7 @@ class ZormQueryBuilder extends Promise {
273
275
  else {
274
276
  this.queryBuilder.innerJoin(`${this.entityAlias}.${relation}`, alias);
275
277
  }
278
+ this.joinedAliases[alias] = relation;
276
279
  return this;
277
280
  }
278
281
  /**
@@ -289,6 +292,7 @@ class ZormQueryBuilder extends Promise {
289
292
  else {
290
293
  this.queryBuilder.leftJoin(`${this.entityAlias}.${relation}`, alias);
291
294
  }
295
+ this.joinedAliases[alias] = relation;
292
296
  return this;
293
297
  }
294
298
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuzjs/orm",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "keywords": [
5
5
  "orm",
6
6
  "zuz",