UNPKG

1.09 kBMarkdownView Raw
1bookshelf-schema
2================
3
4[![Documentation](https://readthedocs.org/projects/bookshelf-schema/badge/)](http://bookshelf-schema.readthedocs.org/)
5
6The Bookshelf plugin that adds fields, relations, scopes and more to bookshelf models.
7
8Like a [bookshelf-fields](https://github.com/bogus34/bookshelf-fields) but better.
9
10[Documentation on readthedoc.org](http://bookshelf-schema.readthedocs.org/)
11
12Usage
13-----
14
15```coffee
16class 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
27or
28
29```javascript
30User = 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
41Installation
42------------
43
44`npm install bookshelf-schema`
45
46And then
47
48`bookshelf.plugin require('bookshelf-schema')()`