Skip to content

Commit

Permalink
Merge pull request #7 from blah238/bookshelf-0.8.x
Browse files Browse the repository at this point in the history
Reimplement as a plugin for Bookshelf/Knex 0.8.x
  • Loading branch information
blah238 committed Apr 11, 2016
2 parents 64744e5 + bd4c5d4 commit d0f29a7
Show file tree
Hide file tree
Showing 38 changed files with 755 additions and 595 deletions.
7 changes: 7 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"preset": "node-style-guide",
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
"maximumLineLength": null,
"requireTrailingComma": null,
"disallowTrailingComma": true
}
3 changes: 3 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"node": true
}
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,46 @@
> Model & Collection manager for [Bookshelf.js][1] to make it easy to create &
> save deep, nested JSON structures from API requests.
## Installation

npm install bookshelf-manager --save

## Usage

1. Register as a plugin in Bookshelf:

```javascript
bookshelf.plugin('bookshelf-manager');
```

- Optionally, you can pass in an object with a `root` property to read models from a specified directory:

```javascript
bookshelf.plugin('bookshelf-manager', { root: 'path/to/models' });
```

2. Register individual models (not required if you passed in a `root` model directory as above):

```javascript
bookshelf.manager.register(model, modelName);
```

- Note: Also compatible with models registered with the [Bookshelf Registry](https://github.com/tgriesser/bookshelf/wiki/Plugin:-Model-Registry) plugin.

3. Use the methods on `bookshelf.manager` to create, fetch, and save models or collections with support for deeply-nested attributes. E.g.:

```javascript
return bookshelf.manager.create('car', {
features: [
{ name: 'ABS', cost: '1250' },
{ name: 'GPS', cost: '500' }
],
quantity: 1
}).then(function(car) {
// created car should now have the associated features
});
```


## API

Expand All @@ -15,6 +55,7 @@

## Changelog

- v0.1.0 - Reimplement as a plugin for Bookshelf/Knex 0.8.x
- v0.0.10 - Enforce `belongsToMany` IDs
- v0.0.9 - Destroy removed `hasMany` models
- v0.0.8 - Fetch empty collections
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/manager');
module.exports = require('./lib/manager').plugin;
Loading

0 comments on commit d0f29a7

Please sign in to comment.