19#include <nlohmann/json.hpp>
20using json = nlohmann::json;
64 std::vector<nlohmann::json>
all()
const;
72 std::optional<nlohmann::json>
find(
const std::string &
id)
const;
80 bool create(
const nlohmann::json &item);
89 bool update(
const std::string &
id,
const nlohmann::json &updatedItem);
97 bool remove(
const std::string &
id);
106 nlohmann::json
findAsJson(
const std::string &
id)
const;
109 bool save(
const std::string &
id,
const json &data);
113 bool updateFromJson(
const std::string &
id,
const nlohmann::json &updates);
128 template <
typename T>
129 T
getValue(
const std::string &key,
const T &defaultValue = T())
134 printf(
"[FrameworkModel] JsonService not available\n");
138 if (data.contains(key))
140 return data[key].get<T>();
153 template <
typename T>
154 void setValue(
const std::string &key,
const T &value)
159 printf(
"[FrameworkModel] JsonService not available\n");
Lightweight JSON wrapper for persistent config management using StorageManager.
Abstract interface for file and directory storage backends.
static constexpr std::uintptr_t getTypeKey()
Provides a basic JSON-backed record model.
bool load()
Loads the JSON collection from storage.
bool createFromJson(const nlohmann::json &obj)
nlohmann::json deleteAsJson(const std::string &id)
bool updateFromJson(const std::string &id, const nlohmann::json &updates)
nlohmann::json toJson() const
Returns the full collection as a JSON array object.
virtual std::string getIdField() const
Returns the JSON key used as the record ID.
std::optional< nlohmann::json > find(const std::string &id) const
Finds an item by ID.
nlohmann::json collection
In-memory array of records.
JsonService * jsonService
Underlying JSON persistence layer
bool create(const nlohmann::json &item)
Adds a new item to the collection.
bool update(const std::string &id, const nlohmann::json &updatedItem)
Updates an item by ID.
nlohmann::json findAsJson(const std::string &id) const
Finds a single item by ID and returns it as JSON or null.
T getValue(const std::string &key, const T &defaultValue=T())
Reads a single top-level key from the model file.
bool save()
Saves the current collection to storage.
void setValue(const std::string &key, const T &value)
Sets a single top-level key in the model file.
std::string storagePath
File path for this model.
std::vector< nlohmann::json > all() const
Returns all items in the collection.
bool remove(const std::string &id)
Removes an item by ID.
Manages loading and saving of a single JSON document using StorageManager.
nlohmann::json & data()
Access the internal JSON object.