masterrecord 0.3.66 → 0.3.67

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.
@@ -64,7 +64,9 @@
64
64
  "Bash(masterrecord add-migration:*)",
65
65
  "Bash(masterrecord:*)",
66
66
  "Bash(git -C /Users/alexanderrich/Documents/development/bookbaghq/bookbag-training log --oneline --all -- *MASTERRECORD_ISSUE*)",
67
- "Bash(npm ls -g masterrecord 2>&1 | head -5)"
67
+ "Bash(npm ls -g masterrecord 2>&1 | head -5)",
68
+ "Bash(gh pr:*)",
69
+ "Read(//tmp/**)"
68
70
  ],
69
71
  "deny": [],
70
72
  "ask": []
@@ -1,4 +1,6 @@
1
1
  // version 0.0.6
2
+ const { _poolKey } = require('masterrecord/context');
3
+
2
4
  class schema{
3
5
 
4
6
  constructor(context){
@@ -6,12 +8,6 @@ class schema{
6
8
  this._dbEnsured = false;
7
9
  }
8
10
 
9
- _poolKey(type, cfg) {
10
- const host = cfg.host || 'localhost';
11
- const port = cfg.port || (type === 'mysql' ? 3306 : 5432);
12
- return `${type}:${cfg.user}@${host}:${port}/${cfg.database}`;
13
- }
14
-
15
11
  /**
16
12
  * Wait for async database initialization (MySQL/PostgreSQL) to complete.
17
13
  * The context constructor fires off an async pool init that may not have
@@ -93,9 +89,9 @@ class schema{
93
89
 
94
90
  // Check global pool cache first -- another context may have already retried
95
91
  const _pools = global.__MR_POOLS__;
96
- const key = _pools ? this._poolKey('mysql', config) : null;
92
+ const key = _poolKey('mysql', config);
97
93
 
98
- if (_pools && key && _pools.has(key)) {
94
+ if (_pools.has(key)) {
99
95
  const cached = _pools.get(key);
100
96
  cached.refCount++;
101
97
  if (cached.promise) {
@@ -120,9 +116,7 @@ class schema{
120
116
  this.context.db = client;
121
117
 
122
118
  // Register in global pool cache so other contexts can reuse
123
- if (_pools && key) {
124
- _pools.set(key, { client, engine: this.context._SQLEngine, refCount: 1, dbType: 'mysql' });
125
- }
119
+ _pools.set(key, { client, engine: this.context._SQLEngine, refCount: 1, dbType: 'mysql' });
126
120
  console.log('[MySQL] Connection pool ready');
127
121
  }
128
122
 
@@ -174,9 +168,9 @@ class schema{
174
168
 
175
169
  // Check global pool cache first -- another context may have already retried
176
170
  const _pools = global.__MR_POOLS__;
177
- const key = _pools ? this._poolKey('postgres', config) : null;
171
+ const key = _poolKey('postgres', config);
178
172
 
179
- if (_pools && key && _pools.has(key)) {
173
+ if (_pools.has(key)) {
180
174
  const cached = _pools.get(key);
181
175
  cached.refCount++;
182
176
  if (cached.promise) {
@@ -202,9 +196,7 @@ class schema{
202
196
  this.context.db = pool;
203
197
 
204
198
  // Register in global pool cache so other contexts can reuse
205
- if (_pools && key) {
206
- _pools.set(key, { pool, engine: this.context._SQLEngine, client: connection, refCount: 1, dbType: 'postgres' });
207
- }
199
+ _pools.set(key, { pool, engine: this.context._SQLEngine, client: connection, refCount: 1, dbType: 'postgres' });
208
200
  console.log('[PostgreSQL] Connection pool ready');
209
201
  }
210
202
 
package/context.js CHANGED
@@ -2402,4 +2402,7 @@ module.exports = context;
2402
2402
  module.exports.ContextError = ContextError;
2403
2403
  module.exports.ConfigurationError = ConfigurationError;
2404
2404
  module.exports.DatabaseConnectionError = DatabaseConnectionError;
2405
- module.exports.EntityValidationError = EntityValidationError;
2405
+ module.exports.EntityValidationError = EntityValidationError;
2406
+
2407
+ // Export pool key generator for use by schema.js (single source of truth)
2408
+ module.exports._poolKey = _poolKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "masterrecord",
3
- "version": "0.3.66",
3
+ "version": "0.3.67",
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": {