@knorm/knorm
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -0,1 +1,11 @@ | ||
<a name="1.7.1"></a> | ||
## [1.7.1](https://github.com/knorm/knorm/compare/v1.7.0...v1.7.1) (2018-09-25) | ||
### Bug Fixes | ||
* **Field:** handle overloaded Field class in JSON validators ([a0e6964](https://github.com/knorm/knorm/commit/a0e6964)) | ||
<a name="1.7.0"></a> | ||
@@ -2,0 +12,0 @@ # [1.7.0](https://github.com/knorm/knorm/compare/v1.6.2...v1.7.0) (2018-09-23) |
@@ -198,4 +198,4 @@ # Models | ||
User.options: { | ||
query: { where: { type: 'system' } } | ||
User.options = { | ||
query: { where: User.where.notEqual({ type: 'system' }) } | ||
}; | ||
@@ -209,12 +209,33 @@ | ||
For more fine-grained control, you can also override the `Query` class: | ||
You could then have a `SystemUser` model for interacting only with system users: | ||
```js | ||
class SystemUser extends User {} | ||
SystemUser.options = { | ||
query: { where: { type: 'system' } } | ||
}; | ||
SystemUser.fetch().then(console.log); // will only contain system users | ||
``` | ||
For more fine-grained control, you can also override the `Query` class and add | ||
custom query options: | ||
```js | ||
class User extends Model {} | ||
User.Query = class UserQuery extends User.Query { | ||
// add an `onlySystemUsers` query option only for the `User` model | ||
onlySystemUsers() { | ||
return this.where({ type: 'system }); | ||
return this.where({ type: 'system' }); | ||
} | ||
withoutSystemUsers() { | ||
const where = this.constructor.where; | ||
return this.where(where.notEqual({ type: 'system' })); | ||
} | ||
withSystemUsers() { | ||
return this; // doesn't need to do anything, should return all users | ||
} | ||
}; | ||
@@ -224,5 +245,7 @@ | ||
onlySystemUsers: true | ||
}).then(console.log); // will not contain system users | ||
}).then(console.log); // will only contain system users | ||
``` | ||
!> Query options must return `this` to allow chaining | ||
## Model registry | ||
@@ -229,0 +252,0 @@ |
@@ -34,3 +34,4 @@ * [<b>Home</b>](readme.md) | ||
* [LICENSE](license.md) | ||
* [CHANGELOG](changelog.md) | ||
* [<b>LICENSE</b>](license.md) | ||
* [<b>CHANGELOG</b>](changelog.md) | ||
* [<b>CREDITS</b>](credits.md) |
@@ -137,2 +137,3 @@ const { isUUID, isDecimal, isEmail } = require('validator'); | ||
// TODO: write regression tests for `new Field` vs `new this.constructor` | ||
_createSchemaValidators(schema) { | ||
@@ -145,3 +146,3 @@ if (typeof schema === 'string') { | ||
// is item schema | ||
return new Field( | ||
return new this.constructor( | ||
Object.assign({}, schema, { | ||
@@ -174,3 +175,3 @@ name: this.name, | ||
validators[name] = new Field( | ||
validators[name] = new this.constructor( | ||
Object.assign({}, config, { | ||
@@ -177,0 +178,0 @@ name, |
{ | ||
"name": "@knorm/knorm", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "A purely ES6 class-based ORM for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -43,9 +43,2 @@ # @knorm/knorm | ||
## Credits | ||
Knorm is inspired by the [Mongoose JS](http://mongoosejs.com/) and | ||
[Bookshelf.js](http://bookshelfjs.org/) APIs. It was previously a built as a | ||
wrapper around [Knex.js](http://knexjs.org), hence the kn-orm name i.e. knex-orm; | ||
but it now builds it's own SQL via [SQL Bricks.js](http://csnw.github.io/sql-bricks/). | ||
Thank you [Ramsés Cabello](https://twitter.com/ramsescabello) for the logo. | ||
## [Get started](https://knorm.github.io/knorm/#/guides/getting-started?id=getting-started) |
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
451862
59
10241
44