Skip to content

Throw error when using bad WHERE operator #9

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

Merged
merged 1 commit into from
Apr 20, 2015
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
134 changes: 12 additions & 122 deletions dist/js-data-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ module.exports =

var keys = _interopRequire(__webpack_require__(4));

var omit = _interopRequire(__webpack_require__(9));
var omit = _interopRequire(__webpack_require__(5));

var isEmpty = _interopRequire(__webpack_require__(5));
var isEmpty = _interopRequire(__webpack_require__(6));

var upperCase = _interopRequire(__webpack_require__(6));
var upperCase = _interopRequire(__webpack_require__(7));

var underscore = _interopRequire(__webpack_require__(7));
var underscore = _interopRequire(__webpack_require__(8));

var toString = _interopRequire(__webpack_require__(8));
var toString = _interopRequire(__webpack_require__(9));

var DSUtils = JSData.DSUtils;
var P = DSUtils.Promise;
Expand Down Expand Up @@ -150,6 +150,8 @@ module.exports =
query = query.orWhere(field, "in", v);
} else if (op === "|notIn") {
query = query.orWhereNotIn(field, v);
} else {
throw new Error("Operator not found");
}
});
});
Expand Down Expand Up @@ -356,143 +358,31 @@ module.exports =
/* 5 */
/***/ function(module, exports, __webpack_require__) {

module.exports = require("mout/lang/isEmpty");
module.exports = require("mout/object/omit");

/***/ },
/* 6 */
/***/ function(module, exports, __webpack_require__) {

module.exports = require("mout/string/upperCase");
module.exports = require("mout/lang/isEmpty");

/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {

module.exports = require("mout/string/underscore");
module.exports = require("mout/string/upperCase");

/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {

module.exports = require("mout/lang/toString");
module.exports = require("mout/string/underscore");

/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {

var slice = __webpack_require__(10);
var contains = __webpack_require__(11);

/**
* Return a copy of the object, filtered to only contain properties except the blacklisted keys.
*/
function omit(obj, var_keys){
var keys = typeof arguments[1] !== 'string'? arguments[1] : slice(arguments, 1),
out = {};

for (var property in obj) {
if (obj.hasOwnProperty(property) && !contains(keys, property)) {
out[property] = obj[property];
}
}
return out;
}

module.exports = omit;




/***/ },
/* 10 */
/***/ function(module, exports, __webpack_require__) {



/**
* Create slice of source array or array-like object
*/
function slice(arr, start, end){
var len = arr.length;

if (start == null) {
start = 0;
} else if (start < 0) {
start = Math.max(len + start, 0);
} else {
start = Math.min(start, len);
}

if (end == null) {
end = len;
} else if (end < 0) {
end = Math.max(len + end, 0);
} else {
end = Math.min(end, len);
}

var result = [];
while (start < end) {
result.push(arr[start++]);
}

return result;
}

module.exports = slice;




/***/ },
/* 11 */
/***/ function(module, exports, __webpack_require__) {

var indexOf = __webpack_require__(12);

/**
* If array contains values.
*/
function contains(arr, val) {
return indexOf(arr, val) !== -1;
}
module.exports = contains;



/***/ },
/* 12 */
/***/ function(module, exports, __webpack_require__) {



/**
* Array.indexOf
*/
function indexOf(arr, item, fromIndex) {
fromIndex = fromIndex || 0;
if (arr == null) {
return -1;
}

var len = arr.length,
i = fromIndex < 0 ? len + fromIndex : fromIndex;
while (i < len) {
// we iterate over sparse items since there is no way to make it
// work properly on IE 7-8. see #64
if (arr[i] === item) {
return i;
}

i++;
}

return -1;
}

module.exports = indexOf;


module.exports = require("mout/lang/toString");

/***/ }
/******/ ]);
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ function filterQuery(resourceConfig, params) {
query = query.orWhere(field, 'in', v);
} else if (op === '|notIn') {
query = query.orWhereNotIn(field, v);
} else {
throw new Error('Operator not found');
}
});
});
Expand Down
16 changes: 15 additions & 1 deletion test/findAll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('DSSqlAdapter#findAll', function () {
it('should filter users using the "in" operator', function () {
var id;

adapter.findAll(User, {
return adapter.findAll(User, {
where: {
age: {
'in': [30]
Expand All @@ -45,4 +45,18 @@ describe('DSSqlAdapter#findAll', function () {
assert.isFalse(!!destroyedUser);
});
});
it('should throw "Operator not found" error', function () {
var op = '>=<';

assert.throw(function () {
return adapter.findAll(User, {
where: {
name: {
op: 'John'
}
}
});
}
, Error, 'Operator not found');
});
});