masterrecord 0.2.7 → 0.2.8

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.
@@ -1,4 +1,4 @@
1
- // version 0.0.8
1
+ // version 0.0.9
2
2
  // learn more about seeding info - https://www.pauric.blog/Database-Updates-and-Migrations-with-Entity-Framework/
3
3
 
4
4
  var fs = require('fs');
@@ -238,6 +238,9 @@ class Migrations{
238
238
  tables.forEach(function (item, index) {
239
239
  // add new columns for table
240
240
  var columnInfo = tables[index];
241
+ // Always expose each table under its name so templates like
242
+ // this.createTable(table.TableName) can safely access it.
243
+ tableObj[item.name] = columnInfo.new;
241
244
 
242
245
  item.newTables.forEach(function (column, ind) {
243
246
  tableObj[item.name] = columnInfo.new;
@@ -1,4 +1,4 @@
1
- // version 0.0.5
1
+ // version 0.0.6
2
2
  class schema{
3
3
 
4
4
  constructor(context){
@@ -85,7 +85,7 @@ class schema{
85
85
  }
86
86
  }
87
87
  }else{
88
- console.log("Table that your trying to create is undefined. PLease check if there are any changes that need to be made");
88
+ console.log("Table that you're trying to create is undefined. Please check if there are any changes that need to be made");
89
89
  }
90
90
  }
91
91
 
package/mySQLEngine.js CHANGED
@@ -570,8 +570,23 @@ class SQLLiteEngine {
570
570
 
571
571
  _execute(query){
572
572
  console.log("SQL:", query);
573
- this.db.connect(this.db);
574
- return this.db.query(query);
573
+ try{
574
+ this.db.connect(this.db);
575
+ const res = this.db.query(query);
576
+ if(res === null){
577
+ console.error('MySQL execute skipped: connection not defined');
578
+ return null;
579
+ }
580
+ return res;
581
+ }catch(err){
582
+ const code = err && err.code ? err.code : '';
583
+ if(code === 'ER_BAD_DB_ERROR' || code === 'ECONNREFUSED' || code === 'PROTOCOL_CONNECTION_LOST'){
584
+ console.error('MySQL execute skipped: connection not defined');
585
+ return null;
586
+ }
587
+ console.error(err);
588
+ return null;
589
+ }
575
590
  }
576
591
 
577
592
  _run(query){
@@ -1,28 +1,45 @@
1
- // version : 0.0.1
1
+ // version : 0.0.3
2
2
 
3
3
  var MySql = require('sync-mysql2');
4
4
 
5
5
  class MySQLClient {
6
6
  constructor(config) {
7
- this.config = config;
7
+ this.config = config ? { ...config } : {};
8
+ if (this.config && Object.prototype.hasOwnProperty.call(this.config, 'type')) {
9
+ delete this.config.type;
10
+ }
8
11
  this.connection = null;
9
12
  }
10
13
 
11
14
  connect() {
12
- if (!this.connection) {
13
- this.connection = new MySql(this.config);
15
+ try {
16
+ if (!this.connection) {
17
+ const { type, ...safeConfig } = this.config || {};
18
+ this.connection = new MySql(safeConfig);
19
+ }
20
+ } catch (err) {
21
+ // Swallow connection errors and leave connection undefined so callers can react gracefully
22
+ console.error('MySQL connect error:', err && err.code ? err.code : err);
23
+ this.connection = null;
24
+ return null;
14
25
  }
15
26
  }
16
27
 
17
28
  query(sql, params = []) {
18
29
  try {
19
30
  if (!this.connection) {
20
- throw new Error('Database connection not established. Call connect() first.');
31
+ return null;
21
32
  }
22
33
  var jj = this.connection.query(sql);
23
34
  this.connection.finishAll();
24
35
  return jj;
25
36
  } catch (err) {
37
+ // If the underlying driver surfaces bad DB or network errors, normalize to null
38
+ const code = err && err.code ? err.code : '';
39
+ if(code === 'ER_BAD_DB_ERROR' || code === 'ECONNREFUSED' || code === 'PROTOCOL_CONNECTION_LOST'){
40
+ console.error('MySQL query skipped due to connection not defined');
41
+ return null;
42
+ }
26
43
  console.error(err);
27
44
  return null;
28
45
  }
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "app-root-path": "^3.1.0",
10
10
  "better-sqlite3": "^12.4.1"
11
11
  },
12
- "version": "0.2.7",
12
+ "version": "0.2.8",
13
13
  "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 ",
14
14
  "homepage": "https://github.com/Tailor/MasterRecord#readme",
15
15
  "repository": {