meadow 2.0.15 → 2.0.16
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meadow",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "A data access library.",
|
|
5
5
|
"main": "source/Meadow.js",
|
|
6
6
|
"scripts": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"alasql": "^4.1.10",
|
|
50
50
|
"browserify": "^17.0.0",
|
|
51
51
|
"chai": "4.3.10",
|
|
52
|
-
"fable": "^3.
|
|
52
|
+
"fable": "^3.1.18",
|
|
53
53
|
"gulp": "^4.0.2",
|
|
54
54
|
"gulp-babel": "^8.0.0",
|
|
55
55
|
"gulp-sourcemaps": "^3.0.0",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"async": "3.2.5",
|
|
68
|
-
"foxhound": "^2.0.
|
|
68
|
+
"foxhound": "^2.0.13",
|
|
69
69
|
"is-my-json-valid": "2.20.6",
|
|
70
70
|
"npm-check-updates": "^16.14.6",
|
|
71
71
|
"simple-get": "^4.0.1"
|
|
@@ -47,8 +47,18 @@ var meadowBehaviorUpdate = function(pMeadow, pQuery, fCallBack)
|
|
|
47
47
|
switch (pMeadow.schema[i].Type)
|
|
48
48
|
{
|
|
49
49
|
case 'UpdateIDUser':
|
|
50
|
+
// Don't obliterate these from the record if automagic is disabled
|
|
51
|
+
if (!pQuery.query.disableAutoUserStamp)
|
|
52
|
+
{
|
|
53
|
+
pQuery.query.records[0][pMeadow.schema[i].Column] = false;
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
50
56
|
case 'UpdateDate':
|
|
51
|
-
|
|
57
|
+
// Don't obliterate these from the record if automagic is disabled
|
|
58
|
+
if (!pQuery.query.disableAutoDateStamp)
|
|
59
|
+
{
|
|
60
|
+
pQuery.query.records[0][pMeadow.schema[i].Column] = false;
|
|
61
|
+
}
|
|
52
62
|
break;
|
|
53
63
|
}
|
|
54
64
|
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* @author <steven@velozo.com>
|
|
4
|
+
*/
|
|
5
|
+
var MeadowProvider = function ()
|
|
6
|
+
{
|
|
7
|
+
function createNew(pFable)
|
|
8
|
+
{
|
|
9
|
+
// If a valid Fable object isn't passed in, return a constructor
|
|
10
|
+
if (typeof (pFable) !== 'object')
|
|
11
|
+
{
|
|
12
|
+
return { new: createNew };
|
|
13
|
+
}
|
|
14
|
+
var _Fable = pFable;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Build a connection pool, shared within this provider.
|
|
18
|
+
* This may be more performant as a shared object.
|
|
19
|
+
*/
|
|
20
|
+
var getDB = function ()
|
|
21
|
+
{
|
|
22
|
+
if (typeof (_Fable.MeadowMySQLConnectionPool) == 'object')
|
|
23
|
+
{
|
|
24
|
+
// This is where the old-style SQL Connection pool is. Refactor doesn't even look for it anymore
|
|
25
|
+
return _Fable.MeadowMySQLConnectionPool;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// New-style default connection pool provider
|
|
29
|
+
if (typeof (_Fable.MeadowMySQLProvider) == 'object' && _Fable.MeadowMySQLProvider.connected)
|
|
30
|
+
{
|
|
31
|
+
return _Fable.MeadowMySQLProvider.pool;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
var getProvider = function ()
|
|
38
|
+
{
|
|
39
|
+
if (typeof (_Fable.MeadowMySQLConnectionPool) == 'object')
|
|
40
|
+
{
|
|
41
|
+
// This is where the old-style SQL Connection pool is. Refactor doesn't even look for it anymore
|
|
42
|
+
return _Fable.MeadowMySQLConnectionPool;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// New-style default connection pool provider
|
|
46
|
+
if (typeof (_Fable.MeadowMySQLProvider) == 'object')
|
|
47
|
+
{
|
|
48
|
+
return _Fable.MeadowMySQLProvider;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The Meadow marshaller also passes in the Schema as the third parameter, but this is a blunt function ATM.
|
|
55
|
+
var marshalRecordFromSourceToObject = function (pObject, pRecord)
|
|
56
|
+
{
|
|
57
|
+
// For now, crudely assign everything in pRecord to pObject
|
|
58
|
+
// This is safe in this context, and we don't want to slow down marshalling with millions of hasOwnProperty checks
|
|
59
|
+
for (var tmpColumn in pRecord)
|
|
60
|
+
{
|
|
61
|
+
pObject[tmpColumn] = pRecord[tmpColumn];
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
var Create = function (pQuery, fCallback)
|
|
66
|
+
{
|
|
67
|
+
var tmpResult = pQuery.parameters.result;
|
|
68
|
+
|
|
69
|
+
pQuery.setDialect('SQLite').buildCreateQuery();
|
|
70
|
+
|
|
71
|
+
// TODO: Test the query before executing
|
|
72
|
+
if (pQuery.logLevel > 0)
|
|
73
|
+
{
|
|
74
|
+
_Fable.log.trace(pQuery.query.body, pQuery.query.parameters);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getDB().getConnection(function (pError, pDBConnection)
|
|
78
|
+
{
|
|
79
|
+
pDBConnection.query(
|
|
80
|
+
pQuery.query.body,
|
|
81
|
+
pQuery.query.parameters,
|
|
82
|
+
function (pError, pRows)
|
|
83
|
+
{
|
|
84
|
+
pDBConnection.release();
|
|
85
|
+
tmpResult.error = pError;
|
|
86
|
+
tmpResult.value = false;
|
|
87
|
+
try
|
|
88
|
+
{
|
|
89
|
+
tmpResult.value = pRows.insertId;
|
|
90
|
+
}
|
|
91
|
+
catch (pErrorGettingRowcount)
|
|
92
|
+
{
|
|
93
|
+
_Fable.log.warn('Error getting insert ID during create query', { Body: pQuery.query.body, Parameters: pQuery.query.parameters });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
tmpResult.executed = true;
|
|
97
|
+
return fCallback();
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// This is a synchronous read, good for a few records.
|
|
104
|
+
// TODO: Add a pipe-able read for huge sets
|
|
105
|
+
var Read = function (pQuery, fCallback)
|
|
106
|
+
{
|
|
107
|
+
var tmpResult = pQuery.parameters.result;
|
|
108
|
+
|
|
109
|
+
pQuery.setDialect('MySQL').buildReadQuery();
|
|
110
|
+
|
|
111
|
+
if (pQuery.logLevel > 0)
|
|
112
|
+
{
|
|
113
|
+
_Fable.log.trace(pQuery.query.body, pQuery.query.parameters);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
getDB().getConnection(function (pError, pDBConnection)
|
|
117
|
+
{
|
|
118
|
+
pDBConnection.query(
|
|
119
|
+
pQuery.query.body,
|
|
120
|
+
pQuery.query.parameters,
|
|
121
|
+
function (pError, pRows)
|
|
122
|
+
{
|
|
123
|
+
pDBConnection.release();
|
|
124
|
+
tmpResult.error = pError;
|
|
125
|
+
tmpResult.value = pRows;
|
|
126
|
+
tmpResult.executed = true;
|
|
127
|
+
return fCallback();
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
var Update = function (pQuery, fCallback)
|
|
134
|
+
{
|
|
135
|
+
var tmpResult = pQuery.parameters.result;
|
|
136
|
+
|
|
137
|
+
pQuery.setDialect('MySQL').buildUpdateQuery();
|
|
138
|
+
|
|
139
|
+
if (pQuery.logLevel > 0)
|
|
140
|
+
{
|
|
141
|
+
_Fable.log.trace(pQuery.query.body, pQuery.query.parameters);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
getDB().getConnection(function (pError, pDBConnection)
|
|
145
|
+
{
|
|
146
|
+
pDBConnection.query(
|
|
147
|
+
pQuery.query.body,
|
|
148
|
+
pQuery.query.parameters,
|
|
149
|
+
function (pError, pRows)
|
|
150
|
+
{
|
|
151
|
+
pDBConnection.release();
|
|
152
|
+
tmpResult.error = pError;
|
|
153
|
+
tmpResult.value = pRows;
|
|
154
|
+
tmpResult.executed = true;
|
|
155
|
+
return fCallback();
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
var Delete = function (pQuery, fCallback)
|
|
162
|
+
{
|
|
163
|
+
var tmpResult = pQuery.parameters.result;
|
|
164
|
+
|
|
165
|
+
pQuery.setDialect('MySQL').buildDeleteQuery();
|
|
166
|
+
|
|
167
|
+
if (pQuery.logLevel > 0)
|
|
168
|
+
{
|
|
169
|
+
_Fable.log.trace(pQuery.query.body, pQuery.query.parameters);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
getDB().getConnection(function (pError, pDBConnection)
|
|
173
|
+
{
|
|
174
|
+
pDBConnection.query
|
|
175
|
+
(
|
|
176
|
+
pQuery.query.body,
|
|
177
|
+
pQuery.query.parameters,
|
|
178
|
+
function (pError, pRows)
|
|
179
|
+
{
|
|
180
|
+
pDBConnection.release();
|
|
181
|
+
tmpResult.error = pError;
|
|
182
|
+
tmpResult.value = false;
|
|
183
|
+
try
|
|
184
|
+
{
|
|
185
|
+
tmpResult.value = pRows.affectedRows;
|
|
186
|
+
}
|
|
187
|
+
catch (pErrorGettingRowcount)
|
|
188
|
+
{
|
|
189
|
+
_Fable.log.warn('Error getting affected rowcount during delete query', { Body: pQuery.query.body, Parameters: pQuery.query.parameters });
|
|
190
|
+
}
|
|
191
|
+
tmpResult.executed = true;
|
|
192
|
+
return fCallback();
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
var Undelete = function (pQuery, fCallback)
|
|
199
|
+
{
|
|
200
|
+
var tmpResult = pQuery.parameters.result;
|
|
201
|
+
|
|
202
|
+
pQuery.setDialect('MySQL').buildUndeleteQuery();
|
|
203
|
+
|
|
204
|
+
if (pQuery.logLevel > 0)
|
|
205
|
+
{
|
|
206
|
+
_Fable.log.trace(pQuery.query.body, pQuery.query.parameters);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
getDB().getConnection(function (pError, pDBConnection)
|
|
210
|
+
{
|
|
211
|
+
pDBConnection.query
|
|
212
|
+
(
|
|
213
|
+
pQuery.query.body,
|
|
214
|
+
pQuery.query.parameters,
|
|
215
|
+
function (pError, pRows)
|
|
216
|
+
{
|
|
217
|
+
pDBConnection.release();
|
|
218
|
+
tmpResult.error = pError;
|
|
219
|
+
tmpResult.value = false;
|
|
220
|
+
try
|
|
221
|
+
{
|
|
222
|
+
tmpResult.value = pRows.affectedRows;
|
|
223
|
+
}
|
|
224
|
+
catch (pErrorGettingRowcount)
|
|
225
|
+
{
|
|
226
|
+
_Fable.log.warn('Error getting affected rowcount during delete query', { Body: pQuery.query.body, Parameters: pQuery.query.parameters });
|
|
227
|
+
}
|
|
228
|
+
tmpResult.executed = true;
|
|
229
|
+
return fCallback();
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
var Count = function (pQuery, fCallback)
|
|
236
|
+
{
|
|
237
|
+
var tmpResult = pQuery.parameters.result;
|
|
238
|
+
|
|
239
|
+
pQuery.setDialect('MySQL').buildCountQuery();
|
|
240
|
+
|
|
241
|
+
if (pQuery.logLevel > 0)
|
|
242
|
+
{
|
|
243
|
+
_Fable.log.trace(pQuery.query.body, pQuery.query.parameters);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
getDB().getConnection(function (pError, pDBConnection)
|
|
247
|
+
{
|
|
248
|
+
pDBConnection.query(
|
|
249
|
+
pQuery.query.body,
|
|
250
|
+
pQuery.query.parameters,
|
|
251
|
+
// The SQLite library also returns the Fields as the third parameter
|
|
252
|
+
function (pError, pRows)
|
|
253
|
+
{
|
|
254
|
+
pDBConnection.release();
|
|
255
|
+
tmpResult.executed = true;
|
|
256
|
+
tmpResult.error = pError;
|
|
257
|
+
tmpResult.value = false;
|
|
258
|
+
try
|
|
259
|
+
{
|
|
260
|
+
tmpResult.value = pRows[0].RowCount;
|
|
261
|
+
}
|
|
262
|
+
catch (pErrorGettingRowcount)
|
|
263
|
+
{
|
|
264
|
+
_Fable.log.warn('Error getting rowcount during count query', { Body: pQuery.query.body, Parameters: pQuery.query.parameters });
|
|
265
|
+
}
|
|
266
|
+
return fCallback();
|
|
267
|
+
}
|
|
268
|
+
);
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
var tmpNewProvider = (
|
|
273
|
+
{
|
|
274
|
+
marshalRecordFromSourceToObject: marshalRecordFromSourceToObject,
|
|
275
|
+
|
|
276
|
+
Create: Create,
|
|
277
|
+
Read: Read,
|
|
278
|
+
Update: Update,
|
|
279
|
+
Delete: Delete,
|
|
280
|
+
Undelete: Undelete,
|
|
281
|
+
Count: Count,
|
|
282
|
+
|
|
283
|
+
getProvider: getProvider,
|
|
284
|
+
providerCreatesSupported: true,
|
|
285
|
+
|
|
286
|
+
new: createNew
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
return tmpNewProvider;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return createNew();
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
module.exports = new MeadowProvider();
|