#pragma once #include #include "cJSON.h" #include "esp_err.h" // JSON "database": one file per collection under /db, each an object of // id -> record, mirroring the Pi's db/*.json. Collections stay in memory and // are written back (via a temp file and rename) whenever they change. // Mount the www and db partitions and load every collection esp_err_t store_init(void); // Borrowed pointer to the collection object (id -> record); never NULL for a known name cJSON *store_coll(const char *name); bool store_known(const char *name); // Replace a whole collection with a parsed object (takes ownership) and persist it esp_err_t store_replace(const char *name, cJSON *obj); esp_err_t store_save(const char *name); // Next numeric string id for a collection ("1" when empty); writes into buf void store_next_id(const char *name, char *buf, size_t len); // Settings are one flat object (the "settings" collection itself) cJSON *store_settings(void); // Recursive lock around every read or write of the collections (HTTP handlers and the sequencer) void store_lock(void); void store_unlock(void);