You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-4
Original file line number
Diff line number
Diff line change
@@ -148,6 +148,8 @@ You can define one-to-one, one-to-many, and many-to-many relationships using any
148
148
149
149
You need to explicitly define the singular and plural forms of your entities, because I'm not a big fan of applying magic Anglocentric defaults to everything.
150
150
151
+
#### `db.rel.<method>`
152
+
151
153
Once you call `setSchema`, your `db` will be blessed with a `rel` object, which is where you can start using the rest of this plugin's API.
152
154
153
155
#### documentType
@@ -197,7 +199,7 @@ Result:
197
199
}
198
200
```
199
201
200
-
If you want, you can specify an `id`. Otherwise an `id`will be created for you.
202
+
You can optionally specify an `id`, otherwise `relational-pouch` will create an `id` for you. (What's the difference between `id`and `_id`? See below.)
201
203
202
204
```js
203
205
db.rel.save('post', {
@@ -218,7 +220,13 @@ Result:
218
220
219
221
You'll notice the special field `rev`, which is a revision identifier. That'll come into play later.
220
222
221
-
`id` and `rev` are reserved fields when you use this plugin. You shouldn't try to use them for something else. An `id` can be any string or integer.
223
+
#### `id` and `rev` are reserved field names!
224
+
225
+
This plugin uses `id` and `rev`. You shouldn't use those fields for anything else. An `id` can be any string or integer.
226
+
227
+
#### `id` vs `_id`
228
+
229
+
[`id` belongs to `relational-pouch`](https://github.com/pouchdb-community/relational-pouch#how-does-it-work), whereas [`_id`](https://docs.couchdb.org/en/latest/best-practices/documents.html) belongs to PouchDB/PouchDB. `relational-pouch` uses `id` for references to related records. You _can_ put the same value for `id` as `_id`, but if one is autogenerated you might want to autogenerate the other, too. Use-cases vary so do what works for you! See also: `db.rel.parseDocID` and `db.rel.makeDocID`, covered in this README below.
222
230
223
231
### db.rel.find(type)
224
232
@@ -1098,7 +1106,7 @@ How does it work?
1098
1106
1099
1107
A relational Pouch/Couch is just a regular database that has been partitioned by type.
1100
1108
1101
-
So for instance, a document with type `"pokemon"` and id `"1"` might have an actual `_id` like `"pokemon_1"`, whereas a `"trainer"` with id `"2"` might have an actual `_id` like `"trainer_2"`. It's not rocket science.
1109
+
So for instance, a document with type `"pokemon"` and id `"1"` might have an actual `_id` like `"pokemon_1"`, whereas a `"trainer"` with id `"2"` might have an actual `_id` like `"trainer_2"`. Simple, but effective.
1102
1110
1103
1111
What is important is that this plugin leverages the very efficient `allDocs()` API, rather than the slower `query()` API. Also, it joins related documents by simply making extra requests, rather than using native map/reduce joined documents. And it's smart enough to group the requests, so the data is fetched in the fewest posisble number of requests.
1104
1112
@@ -1161,4 +1169,4 @@ This will run the tests automatically and the process will exit with a 0 or a 1
1161
1169
```
1162
1170
- This library now uses Typescript, Webpack and Babel in its build setup. The build creates files in 2 output directories: lib and dist.
1163
1171
- The lib directory will contain the output of `tsc` in esnext mode. So this can be used by Webpack and other module aware systems. These will require Babel transformations if you want to use them, but this way you can specify your own target.
1164
-
- The dist directory contains 2 files, pouchdb.relational-pouch.browser.js and pouchdb.relational-pouch.node.js. These are compiled by webpack with targets ">2%, not ie 11" and "node 10". This should be sufficient for now, but otherwise you can build your own with Webpack.
1172
+
- The dist directory contains 2 files, pouchdb.relational-pouch.browser.js and pouchdb.relational-pouch.node.js. These are compiled by webpack with targets ">2%, not ie 11" and "node 10". This should be sufficient for now, but otherwise you can build your own with Webpack.
0 commit comments