masterrecord 0.3.15 → 0.3.17

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/insertManager.js CHANGED
@@ -71,8 +71,8 @@ class InsertManager {
71
71
  * @param {object} currentModel - Tracked entity to insert
72
72
  * @throws {InsertManagerError} If validation fails
73
73
  */
74
- init(currentModel) {
75
- this.runQueries(currentModel);
74
+ async init(currentModel) {
75
+ await this.runQueries(currentModel);
76
76
  }
77
77
 
78
78
  /**
@@ -81,7 +81,7 @@ class InsertManager {
81
81
  * @param {object} currentModel - Tracked entity to insert
82
82
  * @throws {InsertManagerError} If validation fails or relationships are invalid
83
83
  */
84
- runQueries(currentModel) {
84
+ async runQueries(currentModel) {
85
85
  // Reset validation state for this operation to avoid stale errors
86
86
  if (this._errorModel) {
87
87
  this._errorModel.isValid = true;
@@ -94,8 +94,8 @@ class InsertManager {
94
94
  if (this._errorModel.isValid) {
95
95
  const modelEntity = currentModel.__entity;
96
96
  // TODO: if you try to add belongs to you must have a tag added first. if you dont throw error
97
- currentModel = this.belongsToInsert(currentModel, modelEntity);
98
- const SQL = this._SQLEngine.insert(cleanCurrentModel);
97
+ currentModel = await this.belongsToInsert(currentModel, modelEntity);
98
+ const SQL = await this._SQLEngine.insert(cleanCurrentModel);
99
99
  const primaryKey = tools.getPrimaryKeyObject(currentModel.__entity);
100
100
 
101
101
  // use returned insert id directly; avoid redundant post-insert SELECT
@@ -302,7 +302,7 @@ class InsertManager {
302
302
  * @param {object} modelEntity - Entity definition
303
303
  * @returns {object} Updated model with foreign keys populated
304
304
  */
305
- belongsToInsert(currentModel, modelEntity) {
305
+ async belongsToInsert(currentModel, modelEntity) {
306
306
  for (const entity of Object.keys(modelEntity)) {
307
307
  if (modelEntity[entity].relationshipType === RELATIONSHIP_TYPES.BELONGS_TO) {
308
308
  const foreignKey = modelEntity[entity].foreignKey === undefined
@@ -315,7 +315,7 @@ class InsertManager {
315
315
  newPropertyModel.__entity = tools.getEntity(entity, this._allEntities);
316
316
  const propertyCleanCurrentModel = tools.clearAllProto(newPropertyModel);
317
317
  this.validateEntity(propertyCleanCurrentModel, newPropertyModel, newPropertyModel.__entity);
318
- const propertySQL = this._SQLEngine.insert(newPropertyModel);
318
+ const propertySQL = await this._SQLEngine.insert(newPropertyModel);
319
319
  currentModel[foreignKey] = propertySQL.id;
320
320
  }
321
321
  }
@@ -0,0 +1,44 @@
1
+ // Version 1.0.0 - MySQL async connection manager using mysql2/promise
2
+ const mysql = require('mysql2/promise');
3
+
4
+ class MySQLAsyncClient {
5
+ constructor(config) {
6
+ this.config = {
7
+ host: config.host || 'localhost',
8
+ port: config.port || 3306,
9
+ user: config.user,
10
+ password: config.password,
11
+ database: config.database,
12
+ waitForConnections: true,
13
+ connectionLimit: config.connectionLimit || 10,
14
+ queueLimit: 0
15
+ };
16
+ this.pool = null;
17
+ }
18
+
19
+ async connect() {
20
+ try {
21
+ this.pool = await mysql.createPool(this.config);
22
+ // Test connection
23
+ const connection = await this.pool.getConnection();
24
+ console.log('[MySQL] Connection pool initialized successfully');
25
+ connection.release();
26
+ } catch (error) {
27
+ console.error('[MySQL] Connection failed:', error.message);
28
+ throw error;
29
+ }
30
+ }
31
+
32
+ getPool() {
33
+ return this.pool;
34
+ }
35
+
36
+ async close() {
37
+ if (this.pool) {
38
+ await this.pool.end();
39
+ console.log('[MySQL] Connection pool closed');
40
+ }
41
+ }
42
+ }
43
+
44
+ module.exports = MySQLAsyncClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "masterrecord",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
5
5
  "main": "MasterRecord.js",
6
6
  "bin": {
@@ -31,7 +31,7 @@
31
31
  "glob": "^13.0.0",
32
32
  "deep-object-diff": "^1.1.9",
33
33
  "pg": "^8.17.2",
34
- "sync-mysql2": "^1.0.8",
34
+ "mysql2": "^3.11.5",
35
35
  "app-root-path": "^3.1.0",
36
36
  "better-sqlite3": "^12.6.2"
37
37
  }