Skip to content

Commit 65286bb

Browse files
authored
README: Clarify about relational-pouch's id vs. Pouch's _id (#137)
README: Clarify about relational-pouch's `id` vs. Pouch's `_id`
1 parent c212d67 commit 65286bb

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

README.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ You can define one-to-one, one-to-many, and many-to-many relationships using any
148148

149149
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.
150150

151+
#### `db.rel.<method>`
152+
151153
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.
152154

153155
#### documentType
@@ -197,7 +199,7 @@ Result:
197199
}
198200
```
199201

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.)
201203

202204
```js
203205
db.rel.save('post', {
@@ -218,7 +220,13 @@ Result:
218220

219221
You'll notice the special field `rev`, which is a revision identifier. That'll come into play later.
220222

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.
222230

223231
### db.rel.find(type)
224232

@@ -1098,7 +1106,7 @@ How does it work?
10981106
10991107
A relational Pouch/Couch is just a regular database that has been partitioned by type.
11001108
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.
11021110
11031111
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.
11041112
@@ -1161,4 +1169,4 @@ This will run the tests automatically and the process will exit with a 0 or a 1
11611169
```
11621170
- This library now uses Typescript, Webpack and Babel in its build setup. The build creates files in 2 output directories: lib and dist.
11631171
- 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

Comments
 (0)