masterrecord 0.3.16 → 0.3.18
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/Migrations/cli.js +7 -7
- package/Migrations/schema.js +16 -15
- package/SQLLiteEngine.js +72 -48
- package/context.js +48 -38
- package/deleteManager.js +11 -11
- package/insertManager.js +7 -7
- package/mySQLAsyncConnect.js +44 -0
- package/package.json +2 -2
- package/realMySQLEngine.js +836 -0
- package/test/parameterizedPlaceholderTest.js +1 -1
- package/mySQLEngine.js +0 -1105
- package/mySQLSyncConnect.js +0 -82
package/deleteManager.js
CHANGED
|
@@ -26,14 +26,14 @@ class DeleteManager {
|
|
|
26
26
|
* @param {Object|Array} currentModel - Entity or entities to delete
|
|
27
27
|
* @throws {Error} If deletion fails
|
|
28
28
|
*/
|
|
29
|
-
init(currentModel) {
|
|
29
|
+
async init(currentModel) {
|
|
30
30
|
// Input validation
|
|
31
31
|
if (!currentModel) {
|
|
32
32
|
throw new Error('DeleteManager.init() requires a valid model');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
try {
|
|
36
|
-
this.cascadeDelete(currentModel);
|
|
36
|
+
await this.cascadeDelete(currentModel);
|
|
37
37
|
} catch (error) {
|
|
38
38
|
// Add context to error
|
|
39
39
|
const entityName = currentModel.__entity?.__name || 'unknown';
|
|
@@ -46,15 +46,15 @@ class DeleteManager {
|
|
|
46
46
|
* @param {Object|Array} currentModel - Entity or entities to delete
|
|
47
47
|
* @throws {Error} If cascade deletion fails
|
|
48
48
|
*/
|
|
49
|
-
cascadeDelete(currentModel) {
|
|
49
|
+
async cascadeDelete(currentModel) {
|
|
50
50
|
if (!currentModel) {
|
|
51
51
|
return; // Nothing to delete
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if (!Array.isArray(currentModel)) {
|
|
55
|
-
this._deleteSingleEntity(currentModel);
|
|
55
|
+
await this._deleteSingleEntity(currentModel);
|
|
56
56
|
} else {
|
|
57
|
-
this._deleteMultipleEntities(currentModel);
|
|
57
|
+
await this._deleteMultipleEntities(currentModel);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -63,7 +63,7 @@ class DeleteManager {
|
|
|
63
63
|
* @private
|
|
64
64
|
* @param {Object} entity - Entity to delete
|
|
65
65
|
*/
|
|
66
|
-
_deleteSingleEntity(entity) {
|
|
66
|
+
async _deleteSingleEntity(entity) {
|
|
67
67
|
// Validate entity structure
|
|
68
68
|
if (!entity.__entity) {
|
|
69
69
|
throw new Error('Entity missing __entity metadata');
|
|
@@ -90,13 +90,13 @@ class DeleteManager {
|
|
|
90
90
|
}
|
|
91
91
|
} else {
|
|
92
92
|
// Recursively delete related entities
|
|
93
|
-
this.cascadeDelete(relatedModel);
|
|
93
|
+
await this.cascadeDelete(relatedModel);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// Delete the entity itself after cascading
|
|
99
|
-
this._SQLEngine.delete(entity);
|
|
99
|
+
await this._SQLEngine.delete(entity);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
@@ -104,7 +104,7 @@ class DeleteManager {
|
|
|
104
104
|
* @private
|
|
105
105
|
* @param {Array} entities - Array of entities to delete
|
|
106
106
|
*/
|
|
107
|
-
_deleteMultipleEntities(entities) {
|
|
107
|
+
async _deleteMultipleEntities(entities) {
|
|
108
108
|
if (entities.length === 0) {
|
|
109
109
|
return; // Nothing to delete
|
|
110
110
|
}
|
|
@@ -132,13 +132,13 @@ class DeleteManager {
|
|
|
132
132
|
const relatedModel = entity[property];
|
|
133
133
|
|
|
134
134
|
if (relatedModel !== null && relatedModel !== undefined) {
|
|
135
|
-
this.cascadeDelete(relatedModel);
|
|
135
|
+
await this.cascadeDelete(relatedModel);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
// Delete the entity
|
|
141
|
-
this._SQLEngine.delete(entity);
|
|
141
|
+
await this._SQLEngine.delete(entity);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
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.
|
|
3
|
+
"version": "0.3.18",
|
|
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
|
-
"
|
|
34
|
+
"mysql2": "^3.11.5",
|
|
35
35
|
"app-root-path": "^3.1.0",
|
|
36
36
|
"better-sqlite3": "^12.6.2"
|
|
37
37
|
}
|