Skip to content

Commit

Permalink
Mongo emulation mode initial code and tests working correctly when us…
Browse files Browse the repository at this point in the history
…ing find() #43 #46
  • Loading branch information
Irrelon committed Aug 6, 2015
1 parent 935198f commit c2e58e1
Show file tree
Hide file tree
Showing 13 changed files with 550 additions and 5 deletions.
43 changes: 43 additions & 0 deletions js/dist/fdb-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -8364,6 +8364,13 @@ var Matching = {
i;

options = options || {};
queryOptions = queryOptions || {};

// Convert queries from mongo dot notation to forerunner queries
if (queryOptions.$mongoEmulation) {
// Convert string to nested objects
this._convertToFdb(test);
}

// Check if options currently holds a root query object
if (!options.$rootQuery) {
Expand All @@ -8384,6 +8391,8 @@ var Matching = {
}
} else {
// String comparison
// TODO: We can probably use a queryOptions.$locale as a second parameter here
// TODO: to satisfy https://github.com/Irrelon/ForerunnerDB/issues/35
if (source.localeCompare(test)) {
matchedAll = false;
}
Expand Down Expand Up @@ -8575,6 +8584,40 @@ var Matching = {
return matchedAll;
},

_convertToFdb: function (obj) {
var varName,
splitArr,
objCopy,
i;

for (i in obj) {
if (obj.hasOwnProperty(i)) {
objCopy = obj;

if (i.indexOf('.') > -1) {
// Replace .$ with a placeholder before splitting by . char
i = i.replace('.$', '[|$|]');
splitArr = i.split('.');

while ((varName = splitArr.shift())) {
// Replace placeholder back to original .$
varName = varName.replace('[|$|]', '.$');

if (splitArr.length) {
objCopy[varName] = {};
} else {
objCopy[varName] = obj[i];
}

objCopy = objCopy[varName];
}

delete obj[i];
}
}
}
},

/**
* Internal method, performs a matching process against a query operator such as $gt or $nin.
* @param {String} key The property name in the test that matches the operator to perform
Expand Down
43 changes: 43 additions & 0 deletions js/dist/fdb-core+persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -6315,6 +6315,13 @@ var Matching = {
i;

options = options || {};
queryOptions = queryOptions || {};

// Convert queries from mongo dot notation to forerunner queries
if (queryOptions.$mongoEmulation) {
// Convert string to nested objects
this._convertToFdb(test);
}

// Check if options currently holds a root query object
if (!options.$rootQuery) {
Expand All @@ -6335,6 +6342,8 @@ var Matching = {
}
} else {
// String comparison
// TODO: We can probably use a queryOptions.$locale as a second parameter here
// TODO: to satisfy https://github.com/Irrelon/ForerunnerDB/issues/35
if (source.localeCompare(test)) {
matchedAll = false;
}
Expand Down Expand Up @@ -6526,6 +6535,40 @@ var Matching = {
return matchedAll;
},

_convertToFdb: function (obj) {
var varName,
splitArr,
objCopy,
i;

for (i in obj) {
if (obj.hasOwnProperty(i)) {
objCopy = obj;

if (i.indexOf('.') > -1) {
// Replace .$ with a placeholder before splitting by . char
i = i.replace('.$', '[|$|]');
splitArr = i.split('.');

while ((varName = splitArr.shift())) {
// Replace placeholder back to original .$
varName = varName.replace('[|$|]', '.$');

if (splitArr.length) {
objCopy[varName] = {};
} else {
objCopy[varName] = obj[i];
}

objCopy = objCopy[varName];
}

delete obj[i];
}
}
}
},

/**
* Internal method, performs a matching process against a query operator such as $gt or $nin.
* @param {String} key The property name in the test that matches the operator to perform
Expand Down
43 changes: 43 additions & 0 deletions js/dist/fdb-core+views.js
Original file line number Diff line number Diff line change
Expand Up @@ -6577,6 +6577,13 @@ var Matching = {
i;

options = options || {};
queryOptions = queryOptions || {};

// Convert queries from mongo dot notation to forerunner queries
if (queryOptions.$mongoEmulation) {
// Convert string to nested objects
this._convertToFdb(test);
}

// Check if options currently holds a root query object
if (!options.$rootQuery) {
Expand All @@ -6597,6 +6604,8 @@ var Matching = {
}
} else {
// String comparison
// TODO: We can probably use a queryOptions.$locale as a second parameter here
// TODO: to satisfy https://github.com/Irrelon/ForerunnerDB/issues/35
if (source.localeCompare(test)) {
matchedAll = false;
}
Expand Down Expand Up @@ -6788,6 +6797,40 @@ var Matching = {
return matchedAll;
},

_convertToFdb: function (obj) {
var varName,
splitArr,
objCopy,
i;

for (i in obj) {
if (obj.hasOwnProperty(i)) {
objCopy = obj;

if (i.indexOf('.') > -1) {
// Replace .$ with a placeholder before splitting by . char
i = i.replace('.$', '[|$|]');
splitArr = i.split('.');

while ((varName = splitArr.shift())) {
// Replace placeholder back to original .$
varName = varName.replace('[|$|]', '.$');

if (splitArr.length) {
objCopy[varName] = {};
} else {
objCopy[varName] = obj[i];
}

objCopy = objCopy[varName];
}

delete obj[i];
}
}
}
},

/**
* Internal method, performs a matching process against a query operator such as $gt or $nin.
* @param {String} key The property name in the test that matches the operator to perform
Expand Down
43 changes: 43 additions & 0 deletions js/dist/fdb-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5977,6 +5977,13 @@ var Matching = {
i;

options = options || {};
queryOptions = queryOptions || {};

// Convert queries from mongo dot notation to forerunner queries
if (queryOptions.$mongoEmulation) {
// Convert string to nested objects
this._convertToFdb(test);
}

// Check if options currently holds a root query object
if (!options.$rootQuery) {
Expand All @@ -5997,6 +6004,8 @@ var Matching = {
}
} else {
// String comparison
// TODO: We can probably use a queryOptions.$locale as a second parameter here
// TODO: to satisfy https://github.com/Irrelon/ForerunnerDB/issues/35
if (source.localeCompare(test)) {
matchedAll = false;
}
Expand Down Expand Up @@ -6188,6 +6197,40 @@ var Matching = {
return matchedAll;
},

_convertToFdb: function (obj) {
var varName,
splitArr,
objCopy,
i;

for (i in obj) {
if (obj.hasOwnProperty(i)) {
objCopy = obj;

if (i.indexOf('.') > -1) {
// Replace .$ with a placeholder before splitting by . char
i = i.replace('.$', '[|$|]');
splitArr = i.split('.');

while ((varName = splitArr.shift())) {
// Replace placeholder back to original .$
varName = varName.replace('[|$|]', '.$');

if (splitArr.length) {
objCopy[varName] = {};
} else {
objCopy[varName] = obj[i];
}

objCopy = objCopy[varName];
}

delete obj[i];
}
}
}
},

/**
* Internal method, performs a matching process against a query operator such as $gt or $nin.
* @param {String} key The property name in the test that matches the operator to perform
Expand Down
43 changes: 43 additions & 0 deletions js/dist/fdb-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8355,6 +8355,13 @@ var Matching = {
i;

options = options || {};
queryOptions = queryOptions || {};

// Convert queries from mongo dot notation to forerunner queries
if (queryOptions.$mongoEmulation) {
// Convert string to nested objects
this._convertToFdb(test);
}

// Check if options currently holds a root query object
if (!options.$rootQuery) {
Expand All @@ -8375,6 +8382,8 @@ var Matching = {
}
} else {
// String comparison
// TODO: We can probably use a queryOptions.$locale as a second parameter here
// TODO: to satisfy https://github.com/Irrelon/ForerunnerDB/issues/35
if (source.localeCompare(test)) {
matchedAll = false;
}
Expand Down Expand Up @@ -8566,6 +8575,40 @@ var Matching = {
return matchedAll;
},

_convertToFdb: function (obj) {
var varName,
splitArr,
objCopy,
i;

for (i in obj) {
if (obj.hasOwnProperty(i)) {
objCopy = obj;

if (i.indexOf('.') > -1) {
// Replace .$ with a placeholder before splitting by . char
i = i.replace('.$', '[|$|]');
splitArr = i.split('.');

while ((varName = splitArr.shift())) {
// Replace placeholder back to original .$
varName = varName.replace('[|$|]', '.$');

if (splitArr.length) {
objCopy[varName] = {};
} else {
objCopy[varName] = obj[i];
}

objCopy = objCopy[varName];
}

delete obj[i];
}
}
}
},

/**
* Internal method, performs a matching process against a query operator such as $gt or $nin.
* @param {String} key The property name in the test that matches the operator to perform
Expand Down
43 changes: 43 additions & 0 deletions js/lib/Mixin.Matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ var Matching = {
i;

options = options || {};
queryOptions = queryOptions || {};

// Convert queries from mongo dot notation to forerunner queries
if (queryOptions.$mongoEmulation) {
// Convert string to nested objects
this._convertToFdb(test);
}

// Check if options currently holds a root query object
if (!options.$rootQuery) {
Expand All @@ -47,6 +54,8 @@ var Matching = {
}
} else {
// String comparison
// TODO: We can probably use a queryOptions.$locale as a second parameter here
// TODO: to satisfy https://github.com/Irrelon/ForerunnerDB/issues/35
if (source.localeCompare(test)) {
matchedAll = false;
}
Expand Down Expand Up @@ -238,6 +247,40 @@ var Matching = {
return matchedAll;
},

_convertToFdb: function (obj) {
var varName,
splitArr,
objCopy,
i;

for (i in obj) {
if (obj.hasOwnProperty(i)) {
objCopy = obj;

if (i.indexOf('.') > -1) {
// Replace .$ with a placeholder before splitting by . char
i = i.replace('.$', '[|$|]');
splitArr = i.split('.');

while ((varName = splitArr.shift())) {
// Replace placeholder back to original .$
varName = varName.replace('[|$|]', '.$');

if (splitArr.length) {
objCopy[varName] = {};
} else {
objCopy[varName] = obj[i];
}

objCopy = objCopy[varName];
}

delete obj[i];
}
}
}
},

/**
* Internal method, performs a matching process against a query operator such as $gt or $nin.
* @param {String} key The property name in the test that matches the operator to perform
Expand Down
Loading

0 comments on commit c2e58e1

Please sign in to comment.