1 | bookshelf-schema
|
2 | ================
|
3 |
|
4 | [![Documentation](https://readthedocs.org/projects/bookshelf-schema/badge/)](http://bookshelf-schema.readthedocs.org/)
|
5 |
|
6 | The Bookshelf plugin that adds fields, relations, scopes and more to bookshelf models.
|
7 |
|
8 | Like a [bookshelf-fields](https://github.com/bogus34/bookshelf-fields) but better.
|
9 |
|
10 | [Documentation on readthedoc.org](http://bookshelf-schema.readthedocs.org/)
|
11 |
|
12 | Usage
|
13 | -----
|
14 |
|
15 | ```coffee
|
16 | class User extends db.Model
|
17 | tableName: 'users'
|
18 | @schema [
|
19 | EmailField 'email'
|
20 | EncryptedStringField 'password'
|
21 | BooleanField 'active'
|
22 | HasMany 'Photo'
|
23 | Scope 'isActive', -> @where active: true
|
24 | ]
|
25 | ```
|
26 |
|
27 | or
|
28 |
|
29 | ```javascript
|
30 | User = db.Model.extend({ tableName: 'users'}, {
|
31 | schema: [
|
32 | EmailField('email'),
|
33 | EncryptedStringField('password'),
|
34 | BooleanField('active'),
|
35 | HasMany('Photo'),
|
36 | Scope('isActive', function(){ return this.where({active: true}; }))
|
37 | ]
|
38 | });
|
39 | ```
|
40 |
|
41 | Installation
|
42 | ------------
|
43 |
|
44 | `npm install bookshelf-schema`
|
45 |
|
46 | And then
|
47 |
|
48 | `bookshelf.plugin require('bookshelf-schema')()`
|