xref: /6.0.3/couchstore/csdata.md (revision 245f7f5c)
1## Couchstore Data Types
2
3Struct members not listed should be considered internal to Couchstore.
4
5### sized_buf
6    struct sized_buf {
7        char* buf;
8        size_t size;
9    }
10
11Couchstore uses `sized_buf`s to point to data buffers. 
12
13### DocInfo
14    struct DocInfo {
15        sized_buf id;
16        uint64_t db_seq;
17        uint64_t rev_seq;
18        sized_buf rev_meta;
19        int deleted;
20        uint8_t content_meta;
21    }
22
23* `id` - Document ID
24* `db_seq` - Change sequence number the document was inserted at.
25* `rev_seq` - The version number of the document
26* `rev_meta` - Revision metadata. Used by ep-engine to store CAS value, expiry time, and flags
27* `deleted` - 1 if document should be considered "deleted" and not subject to indexing, otherwise 0.
28* `content_meta` - Number field used to store flags indicating metadata about the document content (is it JSON, etc.)
29
30#### The content_meta field
31
32* The least-significant two bits are used to encode why/whether the body is or is not JSON
33  * 0 - Document body *is* JSON
34  * 1 - Inserted data was not valid JSON
35  * 2 - Inserted data was valid JSON, but contained a key reserved for internal use, such as one with a `$` prefix.
36  * 3 - The document was inserted in non-JSON mode.
37* If the most-significant bit is set the document body data has been compressed with snappy. 
38
39When saving documents with `save_doc` or `save_docs`, `id`, `rev_seq`, `rev_meta`, `deleted`, and `content_meta` must be set on the `DocInfo`s passed to Couchstore. The `db_seq` is determined at insert time.
40
41
42### Doc
43    struct Doc {
44        sized_buf id;
45        sized_buf data;
46    }
47
48`id` contains the document ID, `data` contains the document body data. Couchstore does not compress or modify the body data in any way.
49
50### LocalDoc
51    struct LocalDoc {
52        sized_buf id;
53        sized_buf json;
54        int deleted;
55    }
56
57* `id`  - The local document ID, it must start with `_local/`
58* `json` - The local document body.
59* `deleted` - if set to 1 on a LocalDoc passed to save_local_doc, `json` will be ignored, and the local document with the ID in `id` will be removed, if it exists.
60
61
62## C API
63
64Documented in `include/libcouchstore/couch_db.h`
65
66
67