@@ -147,6 +147,8 @@ var User = schema.define('User', {
147
147
restPath: ' /users' // tell WebService adapter which path use as API endpoint
148
148
});
149
149
150
+ var Group = schema .define (' Group' , {name: String });
151
+
150
152
// define any custom method
151
153
User .prototype .getNameAndAge = function () {
152
154
return this .name + ' , ' + this .age ;
@@ -155,7 +157,11 @@ User.prototype.getNameAndAge = function () {
155
157
// models also accessible in schema:
156
158
schema .models .User ;
157
159
schema .models .Post ;
160
+ ```
158
161
162
+ SEE [ schema(3)] ( http://jugglingdb.co/schema.3.html ) for details schema usage.
163
+
164
+ ``` javascript
159
165
// setup relationships
160
166
User .hasMany (Post, {as: ' posts' , foreignKey: ' userId' });
161
167
// creates instance methods:
@@ -169,6 +175,12 @@ Post.belongsTo(User, {as: 'author', foreignKey: 'userId'});
169
175
// post.author() -- sync getter when called without params
170
176
// post.author(user) -- setter when called with object
171
177
178
+ User .hasAndBelongsToMany (' groups' );
179
+ // user.groups(callback) - get groups of user
180
+ // user.groups.create(data, callback) - create new group and connect with user
181
+ // user.groups.add(group, callback) - connect existing group with user
182
+ // user.groups.remove(group, callback) - remove connection between group and user
183
+
172
184
schema .automigrate (); // required only for mysql NOTE: it will drop User and Post tables
173
185
174
186
// work with models:
@@ -208,6 +220,12 @@ User.count([conditions, ]cb)
208
220
user .destroy (cb);
209
221
// destroy all instances
210
222
User .destroyAll (cb);
223
+ ```
224
+
225
+ SEE [ model(3)] ( http://jugglingdb.co/model.3.html ) for more information about
226
+ jugglingdb Model API. Or ` man jugglingdb-model ` in terminal.
227
+
228
+ ``` javascript
211
229
212
230
// Setup validations
213
231
User .validatesPresenceOf (' name' , ' email' )
@@ -225,9 +243,12 @@ user.isValid(function (valid) {
225
243
226
244
```
227
245
228
- ## Callbacks
246
+ SEE ALSO [ jugglingdb-validations(3)] ( http://jugglingdb.co/validations.3.html ) or
247
+ ` man jugglingdb-validations ` in terminal. Validation tests: ./test/validations.test.js
248
+
249
+ ## Hooks
229
250
230
- The following callbacks supported:
251
+ The following hooks supported:
231
252
232
253
- afterInitialize
233
254
- beforeCreate
@@ -279,8 +300,9 @@ User.create(data, callback);
279
300
// callback
280
301
```
281
302
282
- Read the tests for usage examples: ./test/common_test.js
283
- Validations: ./test/validations.test.js
303
+ SEE [ jugglingdb-hooks] ( http://jugglingdb.co/hooks.3.html ) or type this command
304
+ in your fav terminal: ` man jugglingdb-hooks ` . Also check tests for usage
305
+ examples: ./test/hooks.test.js
284
306
285
307
## Your own database adapter
286
308
@@ -290,7 +312,9 @@ To use custom adapter, pass it's package name as first argument to `Schema` cons
290
312
291
313
In that case your adapter should be named as 'jugglingdb-mycouch' npm package.
292
314
293
- ## Testing
315
+ ## Testing [ outdated]
316
+
317
+ TODO: upd this section
294
318
295
319
Core of jugglingdb tests only basic features (database-agnostic) like
296
320
validations, hooks and runs db-specific tests using memory storage. It also
@@ -325,8 +349,30 @@ correctly (host, port, username, password).
325
349
326
350
## Contributing
327
351
328
- If you have found a bug please write unit test, and make sure all other tests still pass before pushing code to repo.
329
-
330
- ## License
331
-
332
- MIT
352
+ If you have found a bug please try to write unit test before reporting. Before
353
+ submit pull request make sure all tests still passed. Check
354
+ [ roadmap] ( http://jugglingdb.co/roadmap.3.html ) , github issues if you want to
355
+ help. Contribution to docs highly appreciated. Contents of man pages and
356
+ http://jugglingdb.co generated from md files stored in this repo at ./docs repo
357
+
358
+ ## MIT License
359
+
360
+ Copyright (C) 2011 by Anatoliy Chakkaev <mail [åt] anatoliy [døt] in>
361
+
362
+ Permission is hereby granted, free of charge, to any person obtaining a copy
363
+ of this software and associated documentation files (the "Software"), to deal
364
+ in the Software without restriction, including without limitation the rights
365
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
366
+ copies of the Software, and to permit persons to whom the Software is
367
+ furnished to do so, subject to the following conditions:
368
+
369
+ The above copyright notice and this permission notice shall be included in
370
+ all copies or substantial portions of the Software.
371
+
372
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
373
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
374
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
375
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
376
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
377
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
378
+ THE SOFTWARE.
0 commit comments