Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement as a plugin for Bookshelf/Knex 0.8.x #7

Merged
merged 11 commits into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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