Comparing version 1.0.9 to 1.0.10
{ | ||
"name": "meadow", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "A data access library.", | ||
@@ -38,3 +38,3 @@ "main": "source/Meadow.js", | ||
"fable": "~1.0.1", | ||
"foxhound": "~1.0.6", | ||
"foxhound": "~1.0.7", | ||
"is-my-json-valid": "2.12.3", | ||
@@ -41,0 +41,0 @@ "mysql2": "0.15.8", |
@@ -18,6 +18,5 @@ // ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
[ | ||
// Step 1: Create the record in the data source | ||
// Step 0: If GUID is specified, make sure the record does not already exist | ||
function (fStageComplete) | ||
{ | ||
pQuery.query.IDUser = pMeadow.userIdentifier; | ||
// Make sure the user submitted a record | ||
@@ -28,2 +27,46 @@ if (!pQuery.query.records) | ||
} | ||
if (pQuery.query.records[0][pMeadow.defaultGUIdentifier] && | ||
pQuery.query.records[0][pMeadow.defaultGUIdentifier].length >= 5) //see Foxhound mysql build create query: GUID min len must be 5 | ||
{ | ||
var tmpGUIDRecord = pQuery.query.records[0][pMeadow.defaultGUIdentifier]; | ||
var tmpQueryRead = pQuery.clone().addFilter(pMeadow.defaultGUIdentifier, tmpGUIDRecord) | ||
.setDisableDeleteTracking(true); //this check is to guarantee uniqueness across the entire table, so always do this | ||
if (pMeadow.rawQueries.checkQuery('Read')) | ||
{ | ||
tmpQueryRead.parameters.queryOverride = pMeadow.rawQueries.getQuery('Read'); | ||
} | ||
pMeadow.provider.Read(tmpQueryRead, function() | ||
{ | ||
var tmpError = tmpQueryRead.error; | ||
console.log('======><',tmpQueryRead.result.value); | ||
if (!tmpError && | ||
tmpQueryRead.result.value.length > 0) | ||
{ | ||
tmpError = 'Record with GUID ' + tmpGUIDRecord + ' already exists!'; | ||
} | ||
if (tmpError) | ||
{ | ||
return fStageComplete(tmpError, tmpQueryRead, tmpQueryRead, tmpQueryRead.result.value); | ||
} | ||
else | ||
{ | ||
return fStageComplete(); | ||
} | ||
}); | ||
} | ||
else | ||
{ | ||
return fStageComplete(); | ||
} | ||
}, | ||
// Step 1: Create the record in the data source | ||
function (fStageComplete) | ||
{ | ||
pQuery.query.IDUser = pMeadow.userIdentifier; | ||
// Merge in the default record with the passed-in record for completeness | ||
@@ -30,0 +73,0 @@ pQuery.query.records[0] = libUnderscore.extend({}, pMeadow.schemaFull.defaultObject, pQuery.query.records[0]); |
@@ -57,2 +57,3 @@ // ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
var _DefaultIdentifier = 'ID'+_Scope; | ||
var _DefaultGUIdentifier = 'GUID'+_Scope; | ||
@@ -193,2 +194,14 @@ | ||
/** | ||
* Set the default globally-unique identifier field name | ||
* | ||
* @method setDefaultGUIdentifier | ||
* @return {Object} This is chainable. | ||
*/ | ||
var setDefaultGUIdentifier = function(pDefaultGUIdentifier) | ||
{ | ||
_DefaultGUIdentifier = pDefaultGUIdentifier; | ||
return this; | ||
}; | ||
/** | ||
* Create a record | ||
@@ -325,2 +338,3 @@ */ | ||
setDefaultIdentifier: setDefaultIdentifier, | ||
setDefaultGUIdentifier: setDefaultGUIdentifier, | ||
setAuthorizer: setAuthorizer, | ||
@@ -385,2 +399,14 @@ | ||
/** | ||
* Default GUIdentifier | ||
* | ||
* @property schema | ||
* @type object | ||
*/ | ||
Object.defineProperty(tmpNewMeadowObject, 'defaultGUIdentifier', | ||
{ | ||
get: function() { return _DefaultGUIdentifier; }, | ||
enumerable: true | ||
}); | ||
/** | ||
* Json Schema | ||
@@ -387,0 +413,0 @@ * |
@@ -23,6 +23,6 @@ /** | ||
// This is queued up for Travis defaults. | ||
Server: "localhost", | ||
Server: "192.168.99.100", | ||
Port: 3306, | ||
User: "root", | ||
Password: "", | ||
User: "admin", | ||
Password: "zKVMD14cPC5N", | ||
Database: "FableTest", | ||
@@ -105,2 +105,3 @@ ConnectionPoolLimit: 20 | ||
.setDefaultIdentifier('IDAnimal') | ||
.setDefaultGUIdentifier('GUIDAnimal') | ||
.setDefault(_AnimalDefault) | ||
@@ -423,2 +424,45 @@ }; | ||
( | ||
'Create a record in the database with a predefined GUID', | ||
function(fDone) | ||
{ | ||
var testMeadow = newMeadow(); | ||
var tmpQuery = testMeadow.query | ||
.setLogLevel(5) | ||
.addRecord({Name:'MewThree', GUIDAnimal:'0x12345', Type:'Pokemon'}); | ||
testMeadow.doCreate(tmpQuery, | ||
function(pError, pQuery, pQueryRead, pRecord) | ||
{ | ||
// We should have a record .... | ||
Expect(pRecord.Name) | ||
.to.equal('MewThree'); | ||
fDone(); | ||
} | ||
) | ||
} | ||
); | ||
test | ||
( | ||
'Create a record in the database with a previously predefined GUID -- expect failure', | ||
function(fDone) | ||
{ | ||
var testMeadow = newMeadow(); | ||
var tmpQuery = testMeadow.query | ||
.setLogLevel(5) | ||
.addRecord({Name:'MewThree', GUIDAnimal:'0x12345', Type:'Pokemon'}); | ||
testMeadow.doCreate(tmpQuery, | ||
function(pError, pQuery, pQueryRead, pRecord) | ||
{ | ||
Expect(pError) | ||
.to.equal("Record with GUID 0x12345 already exists!"); | ||
fDone(); | ||
} | ||
) | ||
} | ||
); | ||
test | ||
( | ||
'Read a record from the database', | ||
@@ -526,5 +570,5 @@ function(fDone) | ||
{ | ||
// There should be 6 records | ||
// There should be 7 records | ||
Expect(pRecord) | ||
.to.equal(6); | ||
.to.equal(7); | ||
fDone(); | ||
@@ -535,2 +579,25 @@ } | ||
); | ||
test | ||
( | ||
'Read a record from the database that had a defined GUID', | ||
function(fDone) | ||
{ | ||
var testMeadow = newMeadow(); | ||
var tmpQuery = testMeadow.query | ||
.addFilter('GUIDAnimal', '0x12345'); | ||
testMeadow.doRead(tmpQuery, | ||
function(pError, pQuery, pRecord) | ||
{ | ||
// We should have a record .... | ||
Expect(pRecord.IDAnimal) | ||
.to.equal(10); | ||
Expect(pRecord.Name) | ||
.to.equal('MewThree'); | ||
fDone(); | ||
} | ||
) | ||
} | ||
); | ||
} | ||
@@ -537,0 +604,0 @@ ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90092
3081
Updatedfoxhound@~1.0.7