@knorm/knorm
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,1 +1,11 @@ | ||
<a name="1.0.1"></a> | ||
## [1.0.1](https://github.com/knorm/knorm/compare/v1.0.0...v1.0.1) (2018-07-05) | ||
### Bug Fixes | ||
* **Query:** add validation for undefined `where` values ([de888d8](https://github.com/knorm/knorm/commit/de888d8)) | ||
<a name="1.0.0"></a> | ||
@@ -2,0 +12,0 @@ # [1.0.0](https://github.com/knorm/knorm/compare/v1.0.0-next...v1.0.0) (2018-06-27) |
@@ -254,6 +254,16 @@ const { difference } = require('lodash'); | ||
getWhere(where, { type } = {}) { | ||
getWhere(where, options = {}) { | ||
const [field, value, ...rest] = where; | ||
if (isString(field)) { | ||
const { type, forHaving } = options; | ||
if (value === undefined) { | ||
throw new this.constructor.QueryError( | ||
`${this.model.name}: undefined "${ | ||
forHaving ? 'having' : 'where' | ||
}" value passed for field \`${field}\`` | ||
); | ||
} | ||
// TODO: upstream `in` with an empty array to sql-bricks | ||
@@ -268,2 +278,9 @@ if (type === 'in' && !value.length) { | ||
if (type === 'between' && isArray(value)) { | ||
if (!value.length) { | ||
throw new this.constructor.QueryError( | ||
`${ | ||
this.model.name | ||
}: empty array passed for "between" for field \`${field}\`` | ||
); | ||
} | ||
return [column, ...value, ...rest]; | ||
@@ -284,3 +301,6 @@ } | ||
const type = field.slice(3); | ||
const where = this.getWhere(value, { type }); | ||
const where = this.getWhere( | ||
value, | ||
Object.assign(options, { type }) | ||
); | ||
if (where instanceof this.sql) { | ||
@@ -292,3 +312,4 @@ expressions.push(where); | ||
} else { | ||
expressions.push({ [this.getColumn(field)]: value }); | ||
const [column] = this.getWhere([field, value], options); | ||
expressions.push({ [column]: value }); | ||
} | ||
@@ -305,7 +326,7 @@ }); | ||
prepareWhere(sql, fields) { | ||
return sql.where.apply(sql, this.getWhere(fields)); | ||
return sql.where.apply(sql, this.getWhere(fields, { forWhere: true })); | ||
} | ||
prepareHaving(sql, fields) { | ||
return sql.having.apply(sql, this.getWhere(fields)); | ||
return sql.having.apply(sql, this.getWhere(fields, { forHaving: true })); | ||
} | ||
@@ -423,3 +444,5 @@ | ||
throw new this.constructor.QueryError( | ||
'all objects should have the same field count' | ||
`${this.model.name}: all objects for ${ | ||
options.forUpdate ? 'update' : 'insert' | ||
} should have the same number of fields` | ||
); | ||
@@ -426,0 +449,0 @@ } |
{ | ||
"name": "@knorm/knorm", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A purely ES6 class-based ORM for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
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
387847
9300