meadow 1.1.2 → 2.0.2
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/.config/configstore/update-notifier-npm.json +1 -1
- package/.config/luxury-extras/MySQL/Dockerfile +1 -0
- package/.config/luxury-extras/MySQL/MySQL-Laden-Entry.sh +0 -0
- package/.config/luxury-extras/model/documentation/Dictionary.md +18 -0
- package/.config/luxury-extras/model/documentation/Model-Author.md +20 -0
- package/.config/luxury-extras/model/documentation/Model-Book.md +26 -0
- package/.config/luxury-extras/model/documentation/Model-BookAuthorJoin.md +14 -0
- package/.config/luxury-extras/model/documentation/Model-BookPrice.md +25 -0
- package/.config/luxury-extras/model/documentation/Model-Review.md +22 -0
- package/.config/luxury-extras/model/documentation/ModelChangeTracking.md +17 -0
- package/.config/luxury-extras/model/documentation/README.md +1 -0
- package/.config/luxury-extras/model/documentation/diagram/README.md +1 -0
- package/.config/luxury-extras/model/documentation/diagram/Stricture_Output.dot +13 -0
- package/.config/luxury-extras/model/documentation/diagram/Stricture_Output.png +0 -0
- package/.config/luxury-extras/model/json_schema_entities/BookStore-MeadowSchema-Author.json +220 -0
- package/.config/luxury-extras/model/json_schema_entities/BookStore-MeadowSchema-Book.json +268 -0
- package/.config/luxury-extras/model/json_schema_entities/BookStore-MeadowSchema-BookAuthorJoin.json +172 -0
- package/.config/luxury-extras/model/json_schema_entities/BookStore-MeadowSchema-BookPrice.json +260 -0
- package/.config/luxury-extras/model/json_schema_entities/BookStore-MeadowSchema-Review.json +236 -0
- package/.config/luxury-extras/model/json_schema_entities/README.md +1 -0
- package/.config/luxury-extras/model/json_schema_model/BookStore-Extended.json +915 -0
- package/.config/luxury-extras/model/json_schema_model/BookStore-PICT.json +1 -0
- package/.config/luxury-extras/model/json_schema_model/BookStore.json +280 -0
- package/.config/luxury-extras/model/json_schema_model/README.md +1 -0
- package/.config/luxury-extras/model/mysql_create/BookStore-CreateDatabase.mysql.sql +116 -0
- package/.config/luxury-extras/model/mysql_create/README.md +1 -0
- package/{Dockerfile → Dockerfile_LUXURYCode} +16 -1
- package/README.md +19 -5
- package/debug/Harness.js +69 -84
- package/gulpfile.js +83 -0
- package/package.json +24 -17
- package/source/Meadow-Browser-Shim.js +14 -0
- package/source/Meadow-Package.json +1 -1
- package/source/Meadow.js +17 -8
- package/source/behaviors/Meadow-Count.js +2 -2
- package/source/behaviors/Meadow-Create.js +3 -4
- package/source/behaviors/Meadow-Delete.js +2 -2
- package/source/behaviors/Meadow-Read.js +4 -4
- package/source/behaviors/Meadow-Reads.js +4 -3
- package/source/behaviors/Meadow-Undelete.js +42 -0
- package/source/behaviors/Meadow-Update.js +2 -2
- package/source/providers/Meadow-Provider-ALASQL.js +33 -0
- package/source/providers/Meadow-Provider-MeadowEndpoints.js +3 -4
- package/source/providers/Meadow-Provider-MySQL.js +40 -0
- package/source/providers/Meadow-Provider-None.js +8 -0
- package/test/Meadow-Provider-ALASQL.js +38 -14
- package/test/Meadow-Provider-MeadowEndpoints_tests.js +2 -819
- package/test/Meadow-Provider-MySQL_tests.js +49 -13
- package/test/Meadow-Provider-None_tests.js +19 -16
- package/test/Meadow_tests.js +2 -2
package/gulpfile.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// We aren't abstracting this yet but here's the ... "Config"
|
|
4
|
+
const _CONFIG = (
|
|
5
|
+
{
|
|
6
|
+
// The input source file that should be passed to browserify:
|
|
7
|
+
// (if you need to auto-instantiate an object, for instance)
|
|
8
|
+
EntrypointInputSourceFile: `${__dirname}/source/Meadow-Browser-Shim.js`,
|
|
9
|
+
|
|
10
|
+
// The name of the packaged object to be passed to browserify:
|
|
11
|
+
// (browserify sets this to global scope and window.SOMEOBJECTNAMEHERE where SOMEOBJECTNAMEHERE is the string below)
|
|
12
|
+
LibraryObjectName: `Meadow`,
|
|
13
|
+
|
|
14
|
+
// The folder to write the library files and maps out to:
|
|
15
|
+
LibraryOutputFolder: `${__dirname}/dist/`,
|
|
16
|
+
|
|
17
|
+
// The name of the unminified version of the packaged library, for easy debugging:
|
|
18
|
+
LibraryUniminifiedFileName: `meadow.js`,
|
|
19
|
+
|
|
20
|
+
// The name of the minified version of the packaged library, for production release:
|
|
21
|
+
LibraryMinifiedFileName: `meadow.min.js`
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// ---> Boilerplate Browser Uglification and Packaging <--- \\
|
|
25
|
+
|
|
26
|
+
const libBrowserify = require('browserify');
|
|
27
|
+
const libGulp = require('gulp');
|
|
28
|
+
|
|
29
|
+
const libVinylSourceStream = require('vinyl-source-stream');
|
|
30
|
+
const libVinylBuffer = require('vinyl-buffer');
|
|
31
|
+
|
|
32
|
+
const libSourcemaps = require('gulp-sourcemaps');
|
|
33
|
+
const libGulpUtil = require('gulp-util');
|
|
34
|
+
const libBabel = require('gulp-babel');
|
|
35
|
+
const libTerser = require('gulp-terser');
|
|
36
|
+
|
|
37
|
+
// Build the module for the browser
|
|
38
|
+
libGulp.task('minified',
|
|
39
|
+
() => {
|
|
40
|
+
// set up the custom browserify instance for this task
|
|
41
|
+
var tmpBrowserify = libBrowserify(
|
|
42
|
+
{
|
|
43
|
+
entries: _CONFIG.EntrypointInputSourceFile,
|
|
44
|
+
standalone: _CONFIG.LibraryObjectName,
|
|
45
|
+
debug: true
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return tmpBrowserify.bundle()
|
|
49
|
+
.pipe(libVinylSourceStream(_CONFIG.LibraryMinifiedFileName))
|
|
50
|
+
.pipe(libVinylBuffer())
|
|
51
|
+
.pipe(libSourcemaps.init({loadMaps: true}))
|
|
52
|
+
// Add transformation tasks to the pipeline here.
|
|
53
|
+
.pipe(libBabel())
|
|
54
|
+
.pipe(libTerser())
|
|
55
|
+
.on('error', libGulpUtil.log)
|
|
56
|
+
.pipe(libSourcemaps.write('./'))
|
|
57
|
+
.pipe(libGulp.dest(_CONFIG.LibraryOutputFolder));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Build the module for the browser
|
|
61
|
+
libGulp.task('debug',
|
|
62
|
+
() => {
|
|
63
|
+
// set up the custom browserify instance for this task
|
|
64
|
+
var tmpBrowserify = libBrowserify(
|
|
65
|
+
{
|
|
66
|
+
entries: _CONFIG.EntrypointInputSourceFile,
|
|
67
|
+
standalone: _CONFIG.LibraryObjectName,
|
|
68
|
+
debug: true
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return tmpBrowserify.bundle()
|
|
72
|
+
.pipe(libVinylSourceStream(_CONFIG.LibraryUniminifiedFileName))
|
|
73
|
+
.pipe(libVinylBuffer())
|
|
74
|
+
.pipe(libBabel())
|
|
75
|
+
.on('error', libGulpUtil.log)
|
|
76
|
+
.pipe(libGulp.dest(_CONFIG.LibraryOutputFolder));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
libGulp.task
|
|
80
|
+
(
|
|
81
|
+
'build',
|
|
82
|
+
libGulp.series('debug', 'minified')
|
|
83
|
+
);
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meadow",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "A data access library.",
|
|
5
5
|
"main": "source/Meadow.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "node source/Meadow.js",
|
|
8
|
-
"coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
|
|
9
|
-
"test": "./node_modules/mocha/bin/_mocha -u tdd -R spec",
|
|
10
|
-
"tests": "./node_modules/mocha/bin/_mocha -u tdd -R spec --grep",
|
|
11
|
-
"
|
|
12
|
-
"docker-dev-
|
|
8
|
+
"coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -u tdd --exit -R spec",
|
|
9
|
+
"test": "./node_modules/mocha/bin/_mocha -u tdd --exit -R spec",
|
|
10
|
+
"tests": "./node_modules/mocha/bin/_mocha -u tdd --exit -R spec --grep",
|
|
11
|
+
"build": "./node_modules/.bin/gulp build --full-paths",
|
|
12
|
+
"docker-dev-build-image": "docker build ./ -f Dockerfile_LUXURYCode -t retold/meadow:local",
|
|
13
|
+
"docker-dev-run": "docker run -it -d --name meadow-dev -p 127.0.0.1:12342:8080 -p 12106:3306 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/meadow\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" retold/meadow:local"
|
|
13
14
|
},
|
|
14
15
|
"mocha": {
|
|
15
16
|
"diff": true,
|
|
@@ -44,18 +45,24 @@
|
|
|
44
45
|
},
|
|
45
46
|
"homepage": "https://github.com/stevenvelozo/meadow",
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
48
|
+
"alasql": "^3.1.0",
|
|
49
|
+
"browserify": "^17.0.0",
|
|
50
|
+
"chai": "4.3.7",
|
|
51
|
+
"gulp": "^4.0.2",
|
|
52
|
+
"gulp-babel": "^8.0.0",
|
|
53
|
+
"gulp-sourcemaps": "^3.0.0",
|
|
54
|
+
"gulp-terser": "^2.1.0",
|
|
55
|
+
"fable": "^3.0.11",
|
|
56
|
+
"gulp-util": "^3.0.8",
|
|
57
|
+
"mocha": "10.2.0",
|
|
58
|
+
"nyc": "^15.1.0",
|
|
59
|
+
"vinyl-buffer": "^1.0.1",
|
|
60
|
+
"vinyl-source-stream": "^2.0.0",
|
|
61
|
+
"mysql2": "^3.1.2"
|
|
52
62
|
},
|
|
53
63
|
"dependencies": {
|
|
54
|
-
"async": "2.4
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"is-my-json-valid": "2.16.0",
|
|
58
|
-
"simple-get": "^4.0.1",
|
|
59
|
-
"underscore": "^1.8.3"
|
|
64
|
+
"async": "3.2.4",
|
|
65
|
+
"foxhound": "^2.0.2",
|
|
66
|
+
"is-my-json-valid": "2.20.6"
|
|
60
67
|
}
|
|
61
68
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple browser shim loader - assign the npm module to a window global automatically
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @author <steven@velozo.com>
|
|
6
|
+
*/
|
|
7
|
+
var libNPMModuleWrapper = require('./Meadow.js');
|
|
8
|
+
|
|
9
|
+
if ((typeof(window) === 'object') && !window.hasOwnProperty('Meadow'))
|
|
10
|
+
{
|
|
11
|
+
window.Meadow = libNPMModuleWrapper;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = libNPMModuleWrapper;
|
package/source/Meadow.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
* @author <steven@velozo.com>
|
|
5
5
|
*/
|
|
6
|
-
var libUnderscore = require('underscore');
|
|
7
6
|
var libFoxHound = require('foxhound');
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -43,6 +42,7 @@ var Meadow = function()
|
|
|
43
42
|
var _ReadsBehavior = require('./behaviors/Meadow-Reads.js');
|
|
44
43
|
var _UpdateBehavior = require('./behaviors/Meadow-Update.js');
|
|
45
44
|
var _DeleteBehavior = require('./behaviors/Meadow-Delete.js');
|
|
45
|
+
var _UndeleteBehavior = require('./behaviors/Meadow-Undelete.js');
|
|
46
46
|
var _CountBehavior = require('./behaviors/Meadow-Count.js');
|
|
47
47
|
|
|
48
48
|
// The data provider
|
|
@@ -70,12 +70,12 @@ var Meadow = function()
|
|
|
70
70
|
/**
|
|
71
71
|
* Load a Meadow Package JSON from file, create a Meadow object from it.
|
|
72
72
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
var _MeadowPackageObjectLoader = require('./Meadow-PackageObjectLoader.js');
|
|
74
|
+
var loadFromPackageObject = function(pPackage)
|
|
75
|
+
{
|
|
76
|
+
return _MeadowPackageObjectLoader(this, pPackage);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
79
|
/**
|
|
80
80
|
* Pass relevant state into the provider
|
|
81
81
|
*
|
|
@@ -276,6 +276,14 @@ var Meadow = function()
|
|
|
276
276
|
return _DeleteBehavior(this, pQuery, fCallBack);
|
|
277
277
|
};
|
|
278
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Undelete a record
|
|
281
|
+
*/
|
|
282
|
+
var doUndelete = function(pQuery, fCallBack)
|
|
283
|
+
{
|
|
284
|
+
return _UndeleteBehavior(this, pQuery, fCallBack);
|
|
285
|
+
};
|
|
286
|
+
|
|
279
287
|
/**
|
|
280
288
|
* Count multiple records
|
|
281
289
|
*/
|
|
@@ -321,7 +329,7 @@ var Meadow = function()
|
|
|
321
329
|
var marshalRecordFromSourceToObject = function(pRecord)
|
|
322
330
|
{
|
|
323
331
|
// Create an object from the default schema object
|
|
324
|
-
var tmpNewObject =
|
|
332
|
+
var tmpNewObject = _Fable.Utility.extend({}, _Schema.defaultObject);
|
|
325
333
|
// Now marshal the values from pRecord into tmpNewObject, based on schema
|
|
326
334
|
_Provider.marshalRecordFromSourceToObject(tmpNewObject, pRecord, _Schema.schema);
|
|
327
335
|
// This turns on magical validation
|
|
@@ -366,6 +374,7 @@ var Meadow = function()
|
|
|
366
374
|
doReads: doReads,
|
|
367
375
|
doUpdate: doUpdate,
|
|
368
376
|
doDelete: doDelete,
|
|
377
|
+
doUndelete: doUndelete,
|
|
369
378
|
doCount: doCount,
|
|
370
379
|
|
|
371
380
|
validateObject: _Schema.validateObject,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
* @author <steven@velozo.com>
|
|
5
5
|
*/
|
|
6
|
-
var
|
|
6
|
+
var libAsyncWaterfall = require('async/waterfall');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Meadow Behavior - Count multiple records
|
|
@@ -15,7 +15,7 @@ var meadowBehaviorCount = function(pMeadow, pQuery, fCallBack)
|
|
|
15
15
|
var tmpProfileStart = new Date(); //for profiling query time
|
|
16
16
|
|
|
17
17
|
// Count the record(s) from the source
|
|
18
|
-
|
|
18
|
+
libAsyncWaterfall(
|
|
19
19
|
[
|
|
20
20
|
// Step 1: Get the record countfrom the data source
|
|
21
21
|
function (fStageComplete)
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
* @author <steven@velozo.com>
|
|
5
5
|
*/
|
|
6
|
-
var
|
|
7
|
-
var libUnderscore = require('underscore');
|
|
6
|
+
var libAsyncWaterfall = require('async/waterfall');
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Meadow Behavior - Create
|
|
@@ -13,7 +12,7 @@ var libUnderscore = require('underscore');
|
|
|
13
12
|
*/
|
|
14
13
|
var meadowBehaviorCreate = function(pMeadow, pQuery, fCallBack)
|
|
15
14
|
{
|
|
16
|
-
|
|
15
|
+
libAsyncWaterfall(
|
|
17
16
|
[
|
|
18
17
|
// Step 0: If GUID is specified, make sure the record does not already exist
|
|
19
18
|
function (fStageComplete)
|
|
@@ -78,7 +77,7 @@ var meadowBehaviorCreate = function(pMeadow, pQuery, fCallBack)
|
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
// Merge in the default record with the passed-in record for completeness
|
|
81
|
-
pQuery.query.records[0] =
|
|
80
|
+
pQuery.query.records[0] = pMeadow.fable.Utility.extend({}, pMeadow.schemaFull.defaultObject, pQuery.query.records[0]);
|
|
82
81
|
// Create override is too complex ... punting for now
|
|
83
82
|
// if (pMeadow.rawQueries.checkQuery('Create'))
|
|
84
83
|
// pQuery.parameters.queryOverride = pMeadow.rawQueries.getQuery('Create');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
* @author <steven@velozo.com>
|
|
5
5
|
*/
|
|
6
|
-
var
|
|
6
|
+
var libAsyncWaterfall = require('async/waterfall');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Meadow Behavior - Delete a single record
|
|
@@ -14,7 +14,7 @@ var meadowBehaviorDelete = function(pMeadow, pQuery, fCallBack)
|
|
|
14
14
|
{
|
|
15
15
|
// TODO: Check if this recordset has implicit delete tracking, branch in this module.
|
|
16
16
|
// Delete the record(s) from the source
|
|
17
|
-
|
|
17
|
+
libAsyncWaterfall(
|
|
18
18
|
[
|
|
19
19
|
// Step 1: Delete the record
|
|
20
20
|
function (fStageComplete)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
* @author <steven@velozo.com>
|
|
5
5
|
*/
|
|
6
|
-
var
|
|
6
|
+
var libAsyncWaterfall = require('async/waterfall');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Meadow Behavior - Read a single record
|
|
@@ -13,7 +13,7 @@ var libAsync = require('async');
|
|
|
13
13
|
var meadowBehaviorRead = function(pMeadow, pQuery, fCallBack)
|
|
14
14
|
{
|
|
15
15
|
// Read the record from the source
|
|
16
|
-
|
|
16
|
+
libAsyncWaterfall(
|
|
17
17
|
[
|
|
18
18
|
// Step 1: Get the record from the data source
|
|
19
19
|
function (fStageComplete)
|
|
@@ -31,7 +31,7 @@ var meadowBehaviorRead = function(pMeadow, pQuery, fCallBack)
|
|
|
31
31
|
// Check that a record was returned
|
|
32
32
|
if (pQuery.parameters.result.value.length < 1)
|
|
33
33
|
{
|
|
34
|
-
return fStageComplete(
|
|
34
|
+
return fStageComplete(undefined, pQuery, false);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
var tmpRecord = pMeadow.marshalRecordFromSourceToObject(pQuery.result.value[0]);
|
|
@@ -39,7 +39,7 @@ var meadowBehaviorRead = function(pMeadow, pQuery, fCallBack)
|
|
|
39
39
|
fStageComplete(pQuery.result.error, pQuery, tmpRecord);
|
|
40
40
|
}
|
|
41
41
|
],
|
|
42
|
-
|
|
42
|
+
(pError, pQuery, pRecord)=>
|
|
43
43
|
{
|
|
44
44
|
if (pError)
|
|
45
45
|
{
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
* @author <steven@velozo.com>
|
|
5
5
|
*/
|
|
6
|
-
var
|
|
6
|
+
var libAsyncWaterfall = require('async/waterfall');
|
|
7
|
+
var libAsyncEach = require('async/eachSeries');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Meadow Behavior - Read multiple records
|
|
@@ -15,7 +16,7 @@ var meadowBehaviorReads = function(pMeadow, pQuery, fCallBack)
|
|
|
15
16
|
var tmpProfileStart = new Date(); //for profiling query time
|
|
16
17
|
|
|
17
18
|
// Read the record(s) from the source
|
|
18
|
-
|
|
19
|
+
libAsyncWaterfall(
|
|
19
20
|
[
|
|
20
21
|
// Step 1: Get the record(s) from the data source
|
|
21
22
|
function (fStageComplete)
|
|
@@ -38,7 +39,7 @@ var meadowBehaviorReads = function(pMeadow, pQuery, fCallBack)
|
|
|
38
39
|
|
|
39
40
|
var tmpRecords = [];
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
libAsyncEach
|
|
42
43
|
(
|
|
43
44
|
pQuery.parameters.result.value,
|
|
44
45
|
function(pRow, pQueueCallback)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system
|
|
2
|
+
/**
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author <steven@velozo.com>
|
|
5
|
+
*/
|
|
6
|
+
var libAsyncWaterfall = require('async/waterfall');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Meadow Behavior - Undelete a single record
|
|
10
|
+
*
|
|
11
|
+
* @function meadowBehaviorUndelete
|
|
12
|
+
*/
|
|
13
|
+
var meadowBehaviorUndelete = function(pMeadow, pQuery, fCallBack)
|
|
14
|
+
{
|
|
15
|
+
// TODO: Check if this recordset has implicit delete tracking, branch in this module?
|
|
16
|
+
// Undelete the record(s) if they were deleted with a bit
|
|
17
|
+
libAsyncWaterfall(
|
|
18
|
+
[
|
|
19
|
+
// Step 1: Undelete the record
|
|
20
|
+
function (fStageComplete)
|
|
21
|
+
{
|
|
22
|
+
if (pMeadow.rawQueries.checkQuery('Undelete'))
|
|
23
|
+
{
|
|
24
|
+
pQuery.parameters.queryOverride = pMeadow.rawQueries.getQuery('Undelete');
|
|
25
|
+
}
|
|
26
|
+
pMeadow.provider.Undelete(pQuery, function(){ fStageComplete(pQuery.result.error, pQuery, pQuery.result.value); });
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
function(pError, pQuery, pRecord)
|
|
30
|
+
{
|
|
31
|
+
if (pError)
|
|
32
|
+
{
|
|
33
|
+
pMeadow.fable.log.warn('Error during the undelete waterfall', {Error:pError, Message: pError.message, Query: pQuery.query});
|
|
34
|
+
}
|
|
35
|
+
fCallBack(pError, pQuery, pRecord);
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return pMeadow;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports = meadowBehaviorUndelete;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
* @author <steven@velozo.com>
|
|
5
5
|
*/
|
|
6
|
-
var
|
|
6
|
+
var libAsyncWaterfall = require('async/waterfall');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Meadow Behavior - Update a single record
|
|
@@ -13,7 +13,7 @@ var libAsync = require('async');
|
|
|
13
13
|
var meadowBehaviorUpdate = function(pMeadow, pQuery, fCallBack)
|
|
14
14
|
{
|
|
15
15
|
// Update the record(s) from the source
|
|
16
|
-
|
|
16
|
+
libAsyncWaterfall(
|
|
17
17
|
[
|
|
18
18
|
// Step 1: Update the record
|
|
19
19
|
function (fStageComplete)
|
|
@@ -304,6 +304,38 @@ var MeadowProvider = function()
|
|
|
304
304
|
fCallback();
|
|
305
305
|
};
|
|
306
306
|
|
|
307
|
+
var Undelete = function(pQuery, fCallback)
|
|
308
|
+
{
|
|
309
|
+
var tmpResult = pQuery.parameters.result;
|
|
310
|
+
|
|
311
|
+
checkDataExists(pQuery.parameters);
|
|
312
|
+
|
|
313
|
+
pQuery.setDialect('ALASQL').buildUndeleteQuery();
|
|
314
|
+
var fQuery = libALASQL.compile(pQuery.query.body);
|
|
315
|
+
|
|
316
|
+
if (pQuery.logLevel > 0 ||
|
|
317
|
+
_GlobalLogLevel > 0)
|
|
318
|
+
{
|
|
319
|
+
_Fable.log.trace(pQuery.query.body, pQuery.query.parameters);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
try
|
|
323
|
+
{
|
|
324
|
+
tmpResult.error = undefined;
|
|
325
|
+
tmpResult.executed = false;
|
|
326
|
+
|
|
327
|
+
tmpResult.value = fQuery(pQuery.query.parameters);
|
|
328
|
+
|
|
329
|
+
tmpResult.executed = true;
|
|
330
|
+
}
|
|
331
|
+
catch (pError)
|
|
332
|
+
{
|
|
333
|
+
tmpResult.error = pError;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
fCallback();
|
|
337
|
+
};
|
|
338
|
+
|
|
307
339
|
var Count = function(pQuery, fCallback)
|
|
308
340
|
{
|
|
309
341
|
var tmpResult = pQuery.parameters.result;
|
|
@@ -463,6 +495,7 @@ var MeadowProvider = function()
|
|
|
463
495
|
Read: Read,
|
|
464
496
|
Update: Update,
|
|
465
497
|
Delete: Delete,
|
|
498
|
+
Undelete: Undelete,
|
|
466
499
|
Count: Count,
|
|
467
500
|
|
|
468
501
|
new: createNew
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* @author <steven@velozo.com>
|
|
5
5
|
*/
|
|
6
6
|
var libSimpleGet = require('simple-get');
|
|
7
|
-
var libUnderscore = require('underscore');
|
|
8
7
|
|
|
9
8
|
var MeadowProvider = function()
|
|
10
9
|
{
|
|
@@ -50,12 +49,12 @@ var MeadowProvider = function()
|
|
|
50
49
|
let tmpRequestOptions = (
|
|
51
50
|
{
|
|
52
51
|
url: tmpURL,
|
|
53
|
-
headers:
|
|
52
|
+
headers: _Fable.Utility.extend({cookie: ''}, _Headers)
|
|
54
53
|
});
|
|
55
|
-
|
|
54
|
+
|
|
56
55
|
tmpRequestOptions.headers.cookie = _Cookies.join(';');
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
|
|
59
58
|
if (pQuery.logLevel > 0 ||
|
|
60
59
|
_GlobalLogLevel > 0)
|
|
61
60
|
_Fable.log.debug(`Request options built...`,tmpRequestOptions);
|
|
@@ -189,6 +189,45 @@ var MeadowProvider = function()
|
|
|
189
189
|
});
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
+
var Undelete = function(pQuery, fCallback)
|
|
193
|
+
{
|
|
194
|
+
var tmpResult = pQuery.parameters.result;
|
|
195
|
+
|
|
196
|
+
pQuery.setDialect('MySQL').buildUndeleteQuery();
|
|
197
|
+
|
|
198
|
+
if (pQuery.logLevel > 0 ||
|
|
199
|
+
_GlobalLogLevel > 0)
|
|
200
|
+
{
|
|
201
|
+
_Fable.log.trace(pQuery.query.body, pQuery.query.parameters);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
getSQLPool().getConnection(function(pError, pDBConnection)
|
|
205
|
+
{
|
|
206
|
+
pDBConnection.query
|
|
207
|
+
(
|
|
208
|
+
pQuery.query.body,
|
|
209
|
+
pQuery.query.parameters,
|
|
210
|
+
// The MySQL library also returns the Fields as the third parameter
|
|
211
|
+
function(pError, pRows)
|
|
212
|
+
{
|
|
213
|
+
pDBConnection.release();
|
|
214
|
+
tmpResult.error = pError;
|
|
215
|
+
tmpResult.value = false;
|
|
216
|
+
try
|
|
217
|
+
{
|
|
218
|
+
tmpResult.value = pRows.affectedRows;
|
|
219
|
+
}
|
|
220
|
+
catch(pErrorGettingRowcount)
|
|
221
|
+
{
|
|
222
|
+
_Fable.log.warn('Error getting affected rowcount during delete query',{Body:pQuery.query.body, Parameters:pQuery.query.parameters});
|
|
223
|
+
}
|
|
224
|
+
tmpResult.executed = true;
|
|
225
|
+
return fCallback();
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
|
|
192
231
|
var Count = function(pQuery, fCallback)
|
|
193
232
|
{
|
|
194
233
|
var tmpResult = pQuery.parameters.result;
|
|
@@ -235,6 +274,7 @@ var MeadowProvider = function()
|
|
|
235
274
|
Read: Read,
|
|
236
275
|
Update: Update,
|
|
237
276
|
Delete: Delete,
|
|
277
|
+
Undelete: Undelete,
|
|
238
278
|
Count: Count,
|
|
239
279
|
|
|
240
280
|
new: createNew
|
|
@@ -52,6 +52,13 @@ var MeadowProvider = function()
|
|
|
52
52
|
fCallback();
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
var Undelete = function(pQuery, fCallback)
|
|
56
|
+
{
|
|
57
|
+
// This does nothing because it's the none data provider!
|
|
58
|
+
pQuery.parameters.result.executed = true;
|
|
59
|
+
fCallback();
|
|
60
|
+
};
|
|
61
|
+
|
|
55
62
|
var Count = function(pQuery, fCallback)
|
|
56
63
|
{
|
|
57
64
|
// This does nothing because it's the none data provider!
|
|
@@ -67,6 +74,7 @@ var MeadowProvider = function()
|
|
|
67
74
|
Read: Read,
|
|
68
75
|
Update: Update,
|
|
69
76
|
Delete: Delete,
|
|
77
|
+
Undelete: Undelete,
|
|
70
78
|
Count: Count,
|
|
71
79
|
|
|
72
80
|
new: createNew
|
|
@@ -12,20 +12,20 @@ var Chai = require("chai");
|
|
|
12
12
|
var Expect = Chai.expect;
|
|
13
13
|
var Assert = Chai.assert;
|
|
14
14
|
|
|
15
|
-
var libAsync = require('async');
|
|
16
15
|
var libALASQL = require('alasql');
|
|
17
16
|
|
|
18
|
-
var libFable = require('fable')
|
|
17
|
+
var libFable = new (require('fable'))({
|
|
19
18
|
LogStreams:
|
|
20
19
|
[
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
{
|
|
21
|
+
level: 'fatal',
|
|
22
|
+
streamtype:'process.stdout',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
streamtype: 'simpleflatfile',
|
|
26
|
+
level: 'trace',
|
|
27
|
+
path: __dirname+'/../tests.log'
|
|
28
|
+
}
|
|
29
29
|
]
|
|
30
30
|
});
|
|
31
31
|
|
|
@@ -291,6 +291,30 @@ suite
|
|
|
291
291
|
}
|
|
292
292
|
);
|
|
293
293
|
test
|
|
294
|
+
(
|
|
295
|
+
'Undelete a record in the database',
|
|
296
|
+
function(fDone)
|
|
297
|
+
{
|
|
298
|
+
var testMeadow = newMeadow();
|
|
299
|
+
|
|
300
|
+
testMeadow.fable.settings.QueryThresholdWarnTime = 1;
|
|
301
|
+
var tmpQuery = testMeadow.query.addFilter('IDAnimal',3);
|
|
302
|
+
|
|
303
|
+
testMeadow.doUndelete(tmpQuery,
|
|
304
|
+
function(pError, pQuery, pRecord)
|
|
305
|
+
{
|
|
306
|
+
// TODO: Research why this is working but not returning the row count
|
|
307
|
+
Expect(pRecord)
|
|
308
|
+
.to.equal(1);
|
|
309
|
+
|
|
310
|
+
testMeadow.fable.settings.QueryThresholdWarnTime = 1000;
|
|
311
|
+
|
|
312
|
+
fDone();
|
|
313
|
+
}
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
);
|
|
317
|
+
test
|
|
294
318
|
(
|
|
295
319
|
'Count all records from the database',
|
|
296
320
|
function(fDone)
|
|
@@ -303,9 +327,9 @@ suite
|
|
|
303
327
|
testMeadow.doCount(testMeadow.query,
|
|
304
328
|
function(pError, pQuery, pRecord)
|
|
305
329
|
{
|
|
306
|
-
// There should be
|
|
330
|
+
// There should be 6 records
|
|
307
331
|
Expect(pRecord)
|
|
308
|
-
.to.equal(
|
|
332
|
+
.to.equal(6);
|
|
309
333
|
Expect(pQuery.parameters.result.executed)
|
|
310
334
|
.to.equal(true);
|
|
311
335
|
testMeadow.fable.settings.QueryThresholdWarnTime = 1000;
|
|
@@ -518,9 +542,9 @@ suite
|
|
|
518
542
|
testMeadow.doCount(testMeadow.query.setLogLevel(5),
|
|
519
543
|
function(pError, pQuery, pRecord)
|
|
520
544
|
{
|
|
521
|
-
// There should be
|
|
545
|
+
// There should be 7 records .. we undeleted one!
|
|
522
546
|
Expect(pRecord)
|
|
523
|
-
.to.equal(
|
|
547
|
+
.to.equal(7);
|
|
524
548
|
fDone();
|
|
525
549
|
}
|
|
526
550
|
)
|