@knorm/knorm
Advanced tools
Comparing version 1.6.2 to 1.7.0
@@ -0,1 +1,16 @@ | ||
<a name="1.7.0"></a> | ||
# [1.7.0](https://github.com/knorm/knorm/compare/v1.6.2...v1.7.0) (2018-09-23) | ||
### Bug Fixes | ||
* **Field:** support overloaded Query.prototype.sql ([e123a9d](https://github.com/knorm/knorm/commit/e123a9d)) | ||
### Features | ||
* support inserts/updates with raw sql ([8ec7c5b](https://github.com/knorm/knorm/commit/8ec7c5b)) | ||
<a name="1.6.2"></a> | ||
@@ -2,0 +17,0 @@ ## [1.6.2](https://github.com/knorm/knorm/compare/v1.6.1...v1.6.2) (2018-08-23) |
const { isUUID, isDecimal, isEmail } = require('validator'); | ||
const isSet = value => value !== undefined && value !== null; | ||
class Field { | ||
@@ -378,2 +380,3 @@ constructor(config = {}) { | ||
// TODO: support `equals` validator for json fields | ||
validateEquals(value, equals) { | ||
@@ -500,28 +503,30 @@ if (!isSet(value)) { | ||
if (type) { | ||
this.validateTypeIs(value, type); | ||
} | ||
if (!(value instanceof this.knorm.Query.prototype.sql)) { | ||
if (type) { | ||
this.validateTypeIs(value, type); | ||
} | ||
if (minLength) { | ||
this.validateMinLengthIs(value, minLength); | ||
} | ||
if (minLength) { | ||
this.validateMinLengthIs(value, minLength); | ||
} | ||
if (maxLength !== undefined) { | ||
this.validateMaxLengthIs(value, maxLength); | ||
} | ||
if (maxLength !== undefined) { | ||
this.validateMaxLengthIs(value, maxLength); | ||
} | ||
if (oneOf) { | ||
this.validateIsOneOf(value, oneOf); | ||
} | ||
if (oneOf) { | ||
this.validateIsOneOf(value, oneOf); | ||
} | ||
if (equals !== undefined) { | ||
this.validateEquals(value, equals); | ||
} | ||
if (equals !== undefined) { | ||
this.validateEquals(value, equals); | ||
} | ||
if (regex) { | ||
this.validateWithRegex(value, regex); | ||
} | ||
if (regex) { | ||
this.validateWithRegex(value, regex); | ||
} | ||
if (schema) { | ||
await this.validateWithSchema(value, schema, modelInstance); | ||
if (schema) { | ||
await this.validateWithSchema(value, schema, modelInstance); | ||
} | ||
} | ||
@@ -538,3 +543,3 @@ | ||
// depended on by knorm-postgres | ||
// depended on by @knorm/postgres | ||
cast(value, modelInstance, { forSave, forFetch }) { | ||
@@ -572,3 +577,4 @@ if (!this.castors) { | ||
const isSet = value => value !== undefined && value !== null; | ||
Field.knorm = Field.prototype.knorm = null; | ||
Field.models = Field.prototype.models = {}; | ||
@@ -575,0 +581,0 @@ module.exports = Field; |
@@ -28,5 +28,7 @@ class Knorm { | ||
Model.prototype.knorm = Model.knorm = this; | ||
Field.prototype.knorm = Field.knorm = this; | ||
Query.prototype.knorm = Query.knorm = this; | ||
Transaction.prototype.knorm = Transaction.knorm = this; | ||
Field.prototype.models = Field.models = this.models; | ||
Model.prototype.models = Model.models = this.models; | ||
@@ -33,0 +35,0 @@ Query.prototype.models = Query.models = this.models; |
@@ -43,3 +43,3 @@ const { upperFirst, merge } = require('lodash'); | ||
// TODO: make async | ||
// TODO: v2: make async | ||
setDefaults({ fields } = {}) { | ||
@@ -162,3 +162,3 @@ this.getFields(fields).forEach(field => { | ||
// TODO: make async? | ||
// TODO: v2: make async | ||
cast({ fields, forSave, forFetch } = {}) { | ||
@@ -165,0 +165,0 @@ this.getFields(fields).forEach(field => { |
@@ -234,3 +234,3 @@ const { difference } = require('lodash'); | ||
// TODO: remove auto-aliasing (breaking change - @knorm/relations) | ||
// TODO: v2: remove auto-aliasing (breaking change - @knorm/relations) | ||
getTable({ format = true, quote = true } = {}) { | ||
@@ -268,3 +268,3 @@ const table = format | ||
// TODO: strict mode: for fetches, warn if field is unknown and is not a function | ||
// TODO: default `quote` to `true` (breaking change - @knorm/paginate) | ||
// TODO: v2: default `quote` to `true` (breaking change - @knorm/paginate) | ||
getColumn(field, { format = true, quote } = {}) { | ||
@@ -291,3 +291,3 @@ const column = this.config.fieldsToColumns[field]; | ||
// TODO: remove and use formatFieldAlias (breaking change - @knorm/relations) | ||
// TODO: v2: remove and use formatFieldAlias (breaking change - @knorm/relations) | ||
formatAlias(alias, { quote } = {}) { | ||
@@ -485,7 +485,17 @@ alias = `${this.config.alias}.${alias}`; | ||
// depended on by @knorm/postgres | ||
getRowValue({ value }) { | ||
return value; | ||
} | ||
// depended on by @knorm/postgres | ||
getCastFields(fields) { | ||
return fields; | ||
} | ||
// TODO: strict mode: throw if row is empty | ||
async getRow(instance, { forInsert, forUpdate }) { | ||
async getRow(instance, options) { | ||
let fields; | ||
if (forInsert) { | ||
if (options.forInsert) { | ||
instance.setDefaults(); | ||
@@ -500,3 +510,3 @@ | ||
if (forUpdate) { | ||
if (options.forUpdate) { | ||
const filledFields = this.config.fieldNames.filter( | ||
@@ -509,4 +519,8 @@ name => instance[name] !== undefined | ||
await instance.validate({ fields }); | ||
instance.cast({ fields, forSave: true }); | ||
const castFields = this.getCastFields(fields, options); | ||
if (castFields.length) { | ||
instance.cast({ fields: castFields, forSave: true }); | ||
} | ||
const data = instance.getFieldData({ fields }); | ||
@@ -516,3 +530,3 @@ | ||
const column = this.getColumn(field, { format: false, quote: true }); | ||
row[column] = value; | ||
row[column] = this.getRowValue({ field, column, value }, options); | ||
return row; | ||
@@ -594,2 +608,3 @@ }, {}); | ||
// TODO: v2: refactor prepareUpdateBatch => getUpdateBatch | ||
// depended on by knorm-postgres | ||
@@ -596,0 +611,0 @@ prepareUpdateBatch(batch) { |
{ | ||
"name": "@knorm/knorm", | ||
"version": "1.6.2", | ||
"version": "1.7.0", | ||
"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
Sorry, the diff of this file is too big to display
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
450851
10240