@stonyx/orm 0.2.1-beta.80 → 0.2.1-beta.81

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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.2.1-beta.80",
7
+ "version": "0.2.1-beta.81",
8
8
  "description": "",
9
9
  "main": "src/main.js",
10
10
  "type": "module",
package/src/main.js CHANGED
@@ -111,9 +111,9 @@ export default class Orm {
111
111
 
112
112
  if (config.orm.mysql) {
113
113
  const { default: MysqlDB } = await import('./mysql/mysql-db.js');
114
- this.mysqlDb = new MysqlDB();
115
- this.db = this.mysqlDb;
116
- promises.push(this.mysqlDb.init());
114
+ this.sqlDb = new MysqlDB();
115
+ this.db = this.sqlDb;
116
+ promises.push(this.sqlDb.init());
117
117
  } else if (this.options.dbType !== 'none') {
118
118
  const db = new DB();
119
119
  this.db = db;
@@ -131,9 +131,9 @@ export default class Orm {
131
131
  return modelClass?.memory === true;
132
132
  };
133
133
 
134
- // Wire up MySQL reference for on-demand queries from store.find()/findAll()
135
- if (this.mysqlDb) {
136
- Orm.store._mysqlDb = this.mysqlDb;
134
+ // Wire up SQL adapter reference for on-demand queries from store.find()/findAll()
135
+ if (this.sqlDb) {
136
+ Orm.store._sqlDb = this.sqlDb;
137
137
  }
138
138
 
139
139
  Orm.ready = await Promise.all(promises);
@@ -141,11 +141,11 @@ export default class Orm {
141
141
  }
142
142
 
143
143
  async startup() {
144
- if (this.mysqlDb) await this.mysqlDb.startup();
144
+ if (this.sqlDb) await this.sqlDb.startup();
145
145
  }
146
146
 
147
147
  async shutdown() {
148
- if (this.mysqlDb) await this.mysqlDb.shutdown();
148
+ if (this.sqlDb) await this.sqlDb.shutdown();
149
149
  }
150
150
 
151
151
  static get db() {
@@ -110,10 +110,10 @@ export function updateRecord(record, rawData, userOptions={}) {
110
110
  function assignRecordId(modelName, rawData) {
111
111
  if (rawData.id) return;
112
112
 
113
- // In MySQL mode with numeric IDs, defer to MySQL auto-increment
114
- if (Orm.instance?.mysqlDb && !isStringIdModel(modelName)) {
113
+ // In SQL mode with numeric IDs, defer to database auto-increment
114
+ if (Orm.instance?.sqlDb && !isStringIdModel(modelName)) {
115
115
  rawData.id = `__pending_${Date.now()}_${Math.random()}`;
116
- rawData.__pendingMysqlId = true;
116
+ rawData.__pendingSqlId = true;
117
117
  return;
118
118
  }
119
119
 
@@ -352,7 +352,7 @@ export default class MysqlDB {
352
352
  const insertData = this._recordToRow(record, schema);
353
353
 
354
354
  // For auto-increment models, remove the pending ID
355
- const isPendingId = record.__data.__pendingMysqlId;
355
+ const isPendingId = record.__data.__pendingSqlId;
356
356
 
357
357
  if (isPendingId) {
358
358
  delete insertData.id;
@@ -380,7 +380,7 @@ export default class MysqlDB {
380
380
  response.data.id = realId;
381
381
  }
382
382
 
383
- delete record.__data.__pendingMysqlId;
383
+ delete record.__data.__pendingSqlId;
384
384
  }
385
385
  }
386
386
 
@@ -385,9 +385,9 @@ export default class OrmRequest extends Request {
385
385
  // Execute main handler
386
386
  const response = await handler(request, state);
387
387
 
388
- // Persist to MySQL for write operations
389
- if (Orm.instance.mysqlDb && WRITE_OPERATIONS.has(operation)) {
390
- await Orm.instance.mysqlDb.persist(operation, this.model, context, response);
388
+ // Persist to SQL database for write operations
389
+ if (Orm.instance.sqlDb && WRITE_OPERATIONS.has(operation)) {
390
+ await Orm.instance.sqlDb.persist(operation, this.model, context, response);
391
391
  }
392
392
 
393
393
  // Add response and relevant records to context
package/src/store.js CHANGED
@@ -22,15 +22,15 @@ export default class Store {
22
22
  }
23
23
 
24
24
  /**
25
- * Async authoritative read. Always queries MySQL for memory: false models.
25
+ * Async authoritative read. Always queries the SQL database for memory: false models.
26
26
  * For memory: true models, returns from store (already loaded on boot).
27
27
  * @param {string} modelName - The model name
28
28
  * @param {string|number} id - The record ID
29
29
  * @returns {Promise<Record|undefined>}
30
30
  */
31
31
  async find(modelName, id) {
32
- // For views in non-MySQL mode, use view resolver
33
- if (Orm.instance?.isView?.(modelName) && !this._mysqlDb) {
32
+ // For views in non-SQL mode, use view resolver
33
+ if (Orm.instance?.isView?.(modelName) && !this._sqlDb) {
34
34
  const resolver = new ViewResolver(modelName);
35
35
  return resolver.resolveOne(id);
36
36
  }
@@ -40,12 +40,12 @@ export default class Store {
40
40
  return this.get(modelName, id);
41
41
  }
42
42
 
43
- // For memory: false models, always query MySQL
44
- if (this._mysqlDb) {
45
- return this._mysqlDb.findRecord(modelName, id);
43
+ // For memory: false models, always query the SQL database
44
+ if (this._sqlDb) {
45
+ return this._sqlDb.findRecord(modelName, id);
46
46
  }
47
47
 
48
- // Fallback to store (JSON mode or no MySQL)
48
+ // Fallback to store (JSON mode or no SQL adapter)
49
49
  return this.get(modelName, id);
50
50
  }
51
51
 
@@ -57,8 +57,8 @@ export default class Store {
57
57
  * @returns {Promise<Record[]>}
58
58
  */
59
59
  async findAll(modelName, conditions) {
60
- // For views in non-MySQL mode, use view resolver
61
- if (Orm.instance?.isView?.(modelName) && !this._mysqlDb) {
60
+ // For views in non-SQL mode, use view resolver
61
+ if (Orm.instance?.isView?.(modelName) && !this._sqlDb) {
62
62
  const resolver = new ViewResolver(modelName);
63
63
  const records = await resolver.resolveAll();
64
64
 
@@ -75,9 +75,9 @@ export default class Store {
75
75
  return modelStore ? Array.from(modelStore.values()) : [];
76
76
  }
77
77
 
78
- // For memory: false models (or filtered queries), always query MySQL
79
- if (this._mysqlDb) {
80
- return this._mysqlDb.findAll(modelName, conditions);
78
+ // For memory: false models (or filtered queries), always query the SQL database
79
+ if (this._sqlDb) {
80
+ return this._sqlDb.findAll(modelName, conditions);
81
81
  }
82
82
 
83
83
  // Fallback to store (JSON mode) — apply conditions in-memory if provided
@@ -101,8 +101,8 @@ export default class Store {
101
101
  * @returns {Promise<Record[]>}
102
102
  */
103
103
  async query(modelName, conditions = {}) {
104
- if (this._mysqlDb) {
105
- return this._mysqlDb.findAll(modelName, conditions);
104
+ if (this._sqlDb) {
105
+ return this._sqlDb.findAll(modelName, conditions);
106
106
  }
107
107
 
108
108
  // Fallback: filter in-memory store
@@ -125,10 +125,10 @@ export default class Store {
125
125
  _memoryResolver = null;
126
126
 
127
127
  /**
128
- * Set by Orm during init — reference to the MysqlDB instance for on-demand queries.
129
- * @type {MysqlDB|null}
128
+ * Set by Orm during init — reference to the SQL adapter instance for on-demand queries.
129
+ * @type {object|null}
130
130
  */
131
- _mysqlDb = null;
131
+ _sqlDb = null;
132
132
 
133
133
  /**
134
134
  * Check if a model is configured for in-memory storage.