From fa8fe160cf801e34684fc15c2deb918d9bf2bb11 Mon Sep 17 00:00:00 2001 From: Nicolas Carlo Date: Wed, 28 Jan 2015 12:04:42 +0100 Subject: [PATCH 1/3] cherry pick wlNext flag --- lib/adapter.js | 15 ++++++++++++++- lib/collection.js | 14 +++++++++----- lib/query/index.js | 9 +++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/adapter.js b/lib/adapter.js index 53a2128c9..293ee76a3 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -66,7 +66,20 @@ module.exports = (function() { }, auto_reconnect: true, disableDriverBSONSizeCheck: false, - reconnectInterval: 200 + reconnectInterval: 200, + + + // Waterline NEXT + // These are flags that can be toggled today and expose future features. If any of the following are turned + // on the adapter tests will probably not pass. If you toggle these know what you are getting into. + wlNext: { + + // Case sensitive - false + // In the next version of WL queries will be case sensitive by default. + // Set this to true to experiment with that feature today. + caseSensitive: false + + } }, diff --git a/lib/collection.js b/lib/collection.js index 0df516218..d73e4c2ef 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -29,6 +29,10 @@ var Collection = module.exports = function Collection(definition, connection) { // Hold a reference to an active connection this.connection = connection; + // Hold the config object + var connectionConfig = connection.config || {}; + this.config = _.extend({}, connectionConfig.wlNext); + // Hold Indexes this.indexes = []; @@ -60,7 +64,7 @@ Collection.prototype.find = function find(criteria, cb) { // Catch errors from building query and return to the callback try { - query = new Query(criteria, this.schema); + query = new Query(criteria, this.schema, this.config); } catch(err) { return cb(err); } @@ -117,7 +121,7 @@ Collection.prototype.stream = function find(criteria, stream) { // Catch errors from building query and return to the callback try { - query = new Query(criteria, this.schema); + query = new Query(criteria, this.schema, this.config); } catch(err) { return stream.end(err); // End stream } @@ -204,7 +208,7 @@ Collection.prototype.update = function update(criteria, values, cb) { // Catch errors build query and return to the callback try { - query = new Query(criteria, this.schema); + query = new Query(criteria, this.schema, this.config); } catch(err) { return cb(err); } @@ -263,7 +267,7 @@ Collection.prototype.destroy = function destroy(criteria, cb) { // Catch errors build query and return to the callback try { - query = new Query(criteria, this.schema); + query = new Query(criteria, this.schema, this.config); } catch(err) { return cb(err); } @@ -310,7 +314,7 @@ Collection.prototype.count = function count(criteria, cb) { // Catch errors build query and return to the callback try { - query = new Query(criteria, this.schema); + query = new Query(criteria, this.schema, this.config); } catch(err) { return cb(err); } diff --git a/lib/query/index.js b/lib/query/index.js index 4c0bff630..8135365ce 100644 --- a/lib/query/index.js +++ b/lib/query/index.js @@ -16,10 +16,11 @@ var _ = require('lodash'), * Normalizes Waterline queries to work with Mongo. * * @param {Object} options + * @param {Object} [config] * @api private */ -var Query = module.exports = function Query(options, schema) { +var Query = module.exports = function Query(options, schema, config) { // Flag as an aggregate query or not this.aggregate = false; @@ -27,6 +28,9 @@ var Query = module.exports = function Query(options, schema) { // Cache the schema for use in parseTypes this.schema = schema; + // Hold the config object + this.config = config || {}; + // Check for Aggregate Options this.checkAggregate(options); @@ -366,9 +370,10 @@ Query.prototype.parseValue = function parseValue(field, modifier, val) { return val; } + // Only if it's not mongodbID, for most of case usage would like: // user.find('56173df732776c64852f8c91') - if(!validator.isMongoId(val)){ + if(!validator.isMongoId(val) && !this.config.caseSensitive){ // Replace Percent Signs, work in a case insensitive fashion by default val = utils.caseInsensitive(val); val = val.replace(/%/g, '[\\s\\S]*'); From 59e89a8679d0665e498b62007837a1a979e0a60e Mon Sep 17 00:00:00 2001 From: Nicolas Carlo Date: Wed, 28 Jan 2015 12:04:54 +0100 Subject: [PATCH 2/3] Add information into the README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 785af67d5..fec13dc67 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,10 @@ module.exports.adapters = { port: 27017, user: 'username', password: 'password', - database: 'your mongo db name here' + database: 'your mongo db name here', + wlNext: { + caseSensitive: false + } } }; ``` From 904c04fb4bd85e3e2868a87c61bfe3d78278fb72 Mon Sep 17 00:00:00 2001 From: Nicolas Carlo Date: Wed, 28 Jan 2015 12:19:04 +0100 Subject: [PATCH 3/3] cherry pick code comment --- lib/query/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/query/index.js b/lib/query/index.js index 8135365ce..e58eb1596 100644 --- a/lib/query/index.js +++ b/lib/query/index.js @@ -373,6 +373,8 @@ Query.prototype.parseValue = function parseValue(field, modifier, val) { // Only if it's not mongodbID, for most of case usage would like: // user.find('56173df732776c64852f8c91') + // + // Turn wlNext.caseSensitive flag to `true` to enable case sensitive requests when there is no modifier if(!validator.isMongoId(val) && !this.config.caseSensitive){ // Replace Percent Signs, work in a case insensitive fashion by default val = utils.caseInsensitive(val);