11#if DETWS_ENABLE_DOCSTORE
16void detws_docstore_open(DetwsDocStore *ds, DetwsDbm *db)
21bool detws_docstore_put(DetwsDocStore *ds,
const char *
id, uint16_t id_len,
const uint8_t *json, uint32_t json_len)
23 return detws_dbm_put(ds->db,
id, id_len, json, json_len);
26long detws_docstore_get(DetwsDocStore *ds,
const char *
id, uint16_t id_len, uint8_t *buf,
size_t cap)
28 return detws_dbm_get(ds->db,
id, id_len, buf, cap);
31bool detws_docstore_del(DetwsDocStore *ds,
const char *
id, uint16_t id_len)
33 return detws_dbm_del(ds->db,
id, id_len);
36bool detws_docstore_contains(DetwsDocStore *ds,
const char *
id, uint16_t id_len)
38 return detws_dbm_contains(ds->db,
id, id_len);
41uint32_t detws_docstore_count(DetwsDocStore *ds)
43 return detws_dbm_count(ds->db);
46bool detws_docstore_sync(DetwsDocStore *ds)
48 return detws_dbm_sync(ds->db);
53enum class FindKind : uint8_t
70 DetwsDocMatchCb user_cb;
77bool find_cb(
const char *key, uint16_t key_len,
void *vctx)
79 FindCtx *f = (FindCtx *)vctx;
84 const char *json = (
const char *)f->doc;
87 if (f->kind == FindKind::FIND_STR)
89 if (
json_get_str(json, f->field, f->fieldtmp,
sizeof(f->fieldtmp)))
90 match = (strcmp(f->fieldtmp, f->sval) == 0);
92 else if (f->kind == FindKind::FIND_INT)
96 match = (v == f->ival);
102 match = (b == f->bval);
108 if (f->user_cb && !f->user_cb(key, key_len, f->doc, (uint32_t)n, f->user_ctx))
114uint32_t run_find(FindCtx *f)
117 detws_dbm_iterate(f->db, find_cb, f);
122uint32_t detws_docstore_find_str(DetwsDocStore *ds,
const char *field,
const char *value, DetwsDocMatchCb cb,
void *ctx)
127 f.kind = FindKind::FIND_STR;
134uint32_t detws_docstore_find_int(DetwsDocStore *ds,
const char *field,
long value, DetwsDocMatchCb cb,
void *ctx)
139 f.kind = FindKind::FIND_INT;
146uint32_t detws_docstore_find_bool(DetwsDocStore *ds,
const char *field,
bool value, DetwsDocMatchCb cb,
void *ctx)
151 f.kind = FindKind::FIND_BOOL;
#define DETWS_DBM_VAL_MAX
#define DETWS_DOCSTORE_FIELD_MAX
Local JSON document store on the WAL (DETWS_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.