@carno.js/orm 1.0.8 → 1.1.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.
@@ -82,6 +82,8 @@ class SqlBuilder {
82
82
  this.statements.alias = this.getAlias(tableName);
83
83
  this.statements.table = this.qualifyTable(schema, tableName);
84
84
  this.statements.values = this.withUpdatedValues(this.withDefaultValues(processedValues, this.entity), this.entity);
85
+ // Store primary key column name for drivers that need it (e.g., MySQL)
86
+ this.statements.primaryKeyColumnName = this.entity._primaryKeyColumnName || 'id';
85
87
  this.reflectToValues();
86
88
  return this;
87
89
  }
@@ -37,9 +37,10 @@ class BunMysqlDriver extends bun_driver_base_1.BunDriverBase {
37
37
  };
38
38
  }
39
39
  let insertId;
40
+ const primaryKeyColumnName = statement.primaryKeyColumnName || 'id';
40
41
  // Check if ID was manually provided in the values
41
- if (statement.values && statement.values.id) {
42
- insertId = statement.values.id;
42
+ if (statement.values && statement.values[primaryKeyColumnName]) {
43
+ insertId = statement.values[primaryKeyColumnName];
43
44
  }
44
45
  else {
45
46
  // For AUTO_INCREMENT, use LAST_INSERT_ID()
@@ -56,7 +57,7 @@ class BunMysqlDriver extends bun_driver_base_1.BunDriverBase {
56
57
  }
57
58
  const cols = statement.columns.join(', ').replaceAll(`${statement.alias}.`, '');
58
59
  const idValue = this.toDatabaseValue(insertId);
59
- const selectSql = `SELECT ${cols} FROM ${statement.table} WHERE id = ${idValue}`;
60
+ const selectSql = `SELECT ${cols} FROM ${statement.table} WHERE \`${primaryKeyColumnName}\` = ${idValue}`;
60
61
  const selectResult = await context.unsafe(selectSql);
61
62
  return {
62
63
  query: { rows: Array.isArray(selectResult) ? selectResult : [] },
@@ -134,6 +134,7 @@ export type Statement<T> = {
134
134
  joinProperty?: string;
135
135
  fkKey?: string;
136
136
  primaryKey?: string;
137
+ primaryKeyColumnName?: string;
137
138
  originAlias?: string;
138
139
  originProperty?: string;
139
140
  joinEntity?: Function;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carno.js/orm",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "A simple ORM for Carno.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": "a6de8eeed759b63f36dc636184fdd53baac9fbc7"
58
+ "gitHead": "c47945fc03f3c5872b3614b99006180162514bb8"
59
59
  }