16void pc_docstore_open(pc_doc_store *ds, pc_dbm *db)
21bool pc_docstore_put(pc_doc_store *ds,
const char *
id, uint16_t id_len,
const uint8_t *json, uint32_t json_len)
23 return pc_dbm_put(ds->db,
id, id_len, json, json_len);
26long pc_docstore_get(pc_doc_store *ds,
const char *
id, uint16_t id_len, uint8_t *buf,
size_t cap)
28 return pc_dbm_get(ds->db,
id, id_len, buf, cap);
31bool pc_docstore_del(pc_doc_store *ds,
const char *
id, uint16_t id_len)
33 return pc_dbm_del(ds->db,
id, id_len);
36bool pc_docstore_contains(
const pc_doc_store *ds,
const char *
id, uint16_t id_len)
38 return pc_dbm_contains(ds->db,
id, id_len);
41uint32_t pc_docstore_count(
const pc_doc_store *ds)
43 return pc_dbm_count(ds->db);
46bool pc_docstore_sync(pc_doc_store *ds)
48 return pc_dbm_sync(ds->db);
53enum class FindKind : uint8_t
70 pc_doc_match_cb user_cb;
77bool find_cb(
const char *key, uint16_t key_len,
void *vctx)
79 FindCtx *f = (FindCtx *)vctx;
86 const char *json = (
const char *)f->doc;
89 if (f->kind == FindKind::FIND_STR)
91 if (
json_get_str(json, f->field, f->fieldtmp,
sizeof(f->fieldtmp)))
93 match = (strcmp(f->fieldtmp, f->sval) == 0);
96 else if (f->kind == FindKind::FIND_INT)
101 match = (v == f->ival);
109 match = (b == f->bval);
116 if (f->user_cb && !f->user_cb(key, key_len, f->doc, (uint32_t)n, f->user_ctx))
124uint32_t run_find(FindCtx *f)
127 pc_dbm_iterate(f->db, find_cb, f);
132uint32_t pc_docstore_find_str(pc_doc_store *ds,
const char *field,
const char *value, pc_doc_match_cb cb,
void *ctx)
137 f.kind = FindKind::FIND_STR;
144uint32_t pc_docstore_find_int(pc_doc_store *ds,
const char *field,
long value, pc_doc_match_cb cb,
void *ctx)
149 f.kind = FindKind::FIND_INT;
156uint32_t pc_docstore_find_bool(pc_doc_store *ds,
const char *field,
bool value, pc_doc_match_cb cb,
void *ctx)
161 f.kind = FindKind::FIND_BOOL;
Local JSON document store on the WAL (PC_ENABLE_DOCSTORE, requires DBM + WAL).
bool json_get_str(const char *json, const char *key, char *out, size_t out_cap)
Read a top-level string member from a JSON object body.
bool json_get_bool(const char *json, const char *key, bool *out)
Read a top-level boolean member (true/false) from a JSON object body.
bool json_get_int(const char *json, const char *key, long *out)
Read a top-level integer member from a JSON object body.
Layer 6 (Presentation) - zero-heap JSON: a bounded writer and top-level reader.
#define PC_DOCSTORE_FIELD_MAX