Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wl next #380

Merged
merged 3 commits into from
Jan 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
};
```
Expand Down
15 changes: 14 additions & 1 deletion lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

},

Expand Down
14 changes: 9 additions & 5 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 9 additions & 2 deletions lib/query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ 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;

// Cache the schema for use in parseTypes
this.schema = schema;

// Hold the config object
this.config = config || {};

// Check for Aggregate Options
this.checkAggregate(options);

Expand Down Expand Up @@ -366,9 +370,12 @@ 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)){
//
// 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);
val = val.replace(/%/g, '[\\s\\S]*');
Expand Down