Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 142 lines (102 sloc) 4.625 kb
ae3a107 [docs] update
Paolo Fragomeni authored
1 <img src="https://github.com/flatiron/resourceful/raw/master/resourceful.png" />
2
3 # Synopsis
dd4b107 Marak [docs] Updating README
Marak authored
4
5 - Isomorphic Resource engine for JavaScript
6 - Resources are business logic wrapped in prototypical models with schema and validation
7 - Resources support several data-providers
8 - Memory
9 - File-System
10 - CouchDB
11 - MongoDB
12 - REST
13 - socket.io
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
14
ae3a107 [docs] update
Paolo Fragomeni authored
15 # Status
16
59cee33 Marak [docs] Updating travis build image to use master branch
Marak authored
17 [![Build Status](https://secure.travis-ci.org/flatiron/resourceful.png?branch=master)](http://travis-ci.org/flatiron/resourceful)
ae3a107 [docs] update
Paolo Fragomeni authored
18
19 # Features
20 * Data Validation
21 * Simplified Data Model Management
7c4e8b2 Pavan Kumar Sunkara Added README for relationships
pksunkara authored
22 * [Relationships](#relationships)
eda479d Marak [docs] Improving documentation. Moved several parts of README to Github ...
Marak authored
23 * [Data Provider Extensible](#engines)
ae3a107 [docs] update
Paolo Fragomeni authored
24 * [Simplified Cache Control](#cache)
25
26 # Installation
27
7cb7c57 Charlie Robbins [dist] Bump a bunch of dependencies and remove all trailing whitespace.
indexzero authored
28 ``` bash
4e8efba [docs] update
Paolo Fragomeni authored
29 $ [sudo] npm install resourceful
ae3a107 [docs] update
Paolo Fragomeni authored
30 ```
31
32 # Usage
33
34 ## Simple case
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
35
36 ``` js
4e8efba [docs] update
Paolo Fragomeni authored
37 var resourceful = require('resourceful');
38
39 var Creature = resourceful.define('creature', function () {
40 //
41 // Specify a storage engine
42 //
43 this.use('couchdb');
7cb7c57 Charlie Robbins [dist] Bump a bunch of dependencies and remove all trailing whitespace.
indexzero authored
44
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
45 //
4e8efba [docs] update
Paolo Fragomeni authored
46 // Specify some properties with validation
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
47 //
4e8efba [docs] update
Paolo Fragomeni authored
48 this.string('diet');
49 this.bool('vertebrate');
50 this.array('belly');
51
52 //
53 // Specify timestamp properties
54 //
55 this.timestamps();
56 });
57
58 //
59 // Now that the `Creature` prototype is defined
60 // we can add custom logic to be available on all instances
61 //
62 Creature.prototype.feed = function (food) {
63 this.belly.push(food);
64 };
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
65 ```
ae3a107 [docs] update
Paolo Fragomeni authored
66 <a name="engines"></a>
08d810f Charlie Robbins [doc] Added LICENSE and README.md
indexzero authored
67
7cb7c57 Charlie Robbins [dist] Bump a bunch of dependencies and remove all trailing whitespace.
indexzero authored
68 # Engines
08d810f Charlie Robbins [doc] Added LICENSE and README.md
indexzero authored
69
eda479d Marak [docs] Improving documentation. Moved several parts of README to Github ...
Marak authored
70 ### Documentation
7c4e8b2 Pavan Kumar Sunkara Added README for relationships
pksunkara authored
71
f264d00 Jamund Ferguson Added more documentation links.
xjamundx authored
72 See the [wiki](https://github.com/flatiron/resourceful/wiki) for more documention.
73
188d9aa Marak [fix] Updated wiki links in README
Marak authored
74 * [Engines Usage](https://github.com/flatiron/resourceful/wiki/Engines-Usage)
75 * [Engine Constructor](https://github.com/flatiron/resourceful/wiki/Engine-Constructor)
76 * [Engine Caching](https://github.com/flatiron/resourceful/wiki/Engine-Caching)
f264d00 Jamund Ferguson Added more documentation links.
xjamundx authored
77 * [Relational Resources](https://github.com/flatiron/resourceful/wiki/Relational-Resources)
78 * [Hooks and Events](https://github.com/flatiron/resourceful/wiki/Hooks-and-Events)
7cb7c57 Charlie Robbins [dist] Bump a bunch of dependencies and remove all trailing whitespace.
indexzero authored
79
ae3a107 [docs] update
Paolo Fragomeni authored
80
81 # API
82
7c4e8b2 Pavan Kumar Sunkara Added README for relationships
pksunkara authored
83 ## Resource Constructor Methods
ae3a107 [docs] update
Paolo Fragomeni authored
84 These methods are available on all user-defined resource constructors, as well as on the default `resourceful.Resource` constructor.
08d810f Charlie Robbins [doc] Added LICENSE and README.md
indexzero authored
85
7c4e8b2 Pavan Kumar Sunkara Added README for relationships
pksunkara authored
86 * `Resource.get(id, [callback])`: Fetch a resource by `id`.
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
87 * `Resource.update(id, properties, [callback])`: Update a resource with properties.
7c4e8b2 Pavan Kumar Sunkara Added README for relationships
pksunkara authored
88 * `Resource.destroy(id, [callback])`: Destroy a resource by `id`.
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
89 * `Resource.all([callback])`: Fetches all resources of this type.
b49f884 Juan G. Hurtado Fix typo on "Resource Constructor Methods" section
juanghurtado authored
90 * `Resource.find(properties, [callback])`: Find all resources of this type which satisfy `properties` conditions.
7c4e8b2 Pavan Kumar Sunkara Added README for relationships
pksunkara authored
91 * `Resource.save(inst, [callback])`: Saves the specified resource instance `inst` by overwriting all properties.
92 * `Resource.create(properties, [callback])`: Creates a new instance of the Resource with the specified `properties`.
93 * `Resource.new(properties)`: Instantiates a new instance of the Resource with the `properties`.
08d810f Charlie Robbins [doc] Added LICENSE and README.md
indexzero authored
94
ae3a107 [docs] update
Paolo Fragomeni authored
95 ## Resource Instance Methods
08d810f Charlie Robbins [doc] Added LICENSE and README.md
indexzero authored
96
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
97 * `Resource.prototype.save([callback])`
98 * `Resource.prototype.update(properties, [callback])`
99 * `Resource.prototype.destroy([callback])`
100 * `Resource.prototype.reload([callback])`
08d810f Charlie Robbins [doc] Added LICENSE and README.md
indexzero authored
101
7c4e8b2 Pavan Kumar Sunkara Added README for relationships
pksunkara authored
102 ## Relationship Constructor Methods
103 These methods are available on all user-defined resource constructors which are in a relationship
104
105 * `Parent.children(id, [callback])`: Fetches all the children for the specified `id`.
106 * `Parent.createChild(id, properties, [callback])`: Create a child for `id` with the specified `properties`.
107 * `Child.byParent(id, [callback])`: Fetches all the children for the parent given by `id`.
108
109 ## Relationship Instance Methods
110
111 * `Parent.prototype.children([callback])`
112 * `Parent.prototype.createChild(properties, [callback])`
113 * `Child.prototype.parent([callback])`: Fetches the parent of the given child instance.
114
ff957d1 Marak [docs] Updating README
Marak authored
115 <a name="relationships"></a>
116 # Relational Resources
117
118 Resourceful supports a simple `Resource.parent` API, supports one-one, one-many, and many-many relationships.
119
120 ### Documentation
121
122 * [Relational Resources](https://github.com/flatiron/resourceful/wiki/Relational-Resources)
7bbd9b3 Joshua Holbrook [doc] In-depth documentation on writing engines, including information o...
jfhbrook authored
123
ae3a107 [docs] update
Paolo Fragomeni authored
124 # Tests
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
125 All tests are written with [vows][0] and should be run with [npm][1]:
08d810f Charlie Robbins [doc] Added LICENSE and README.md
indexzero authored
126
ae3a107 [docs] update
Paolo Fragomeni authored
127 ```bash
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
128 $ npm test
129 ```
08d810f Charlie Robbins [doc] Added LICENSE and README.md
indexzero authored
130
d985319 Charlie Robbins [doc] Update README.md and package.json
indexzero authored
131 [0]: http://vowsjs.org
888cd2d Maciej Małecki [docs] Fix example in `README.md`
mmalecki authored
132 [1]: http://npmjs.org
133
ae3a107 [docs] update
Paolo Fragomeni authored
134 # License
135 Copyright 2012 Nodejitsu, Inc.
136
137 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
138
139 http://www.apache.org/licenses/LICENSE-2.0
140
141 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Something went wrong with that request. Please try again.