FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
ns_db Namespace Reference

JSON-based configuration database layer. More...

Namespaces

namespace  ns_bind
 Bind mount configuration management.
 
namespace  ns_boot
 Boot command configuration storage.
 
namespace  ns_desktop
 Desktop integration configuration management.
 
namespace  ns_env
 Environment variable database management.
 
namespace  ns_recipe
 Package recipe configuration management.
 
namespace  ns_remote
 Remote recipe repository URL management.
 

Classes

class  Db
 A type-safe wrapper around nlohmann::json for database operations. More...
 

Typedefs

using object_t = nlohmann::basic_json<>::object_t
 
using KeyType = json_t::value_t
 

Functions

std::ostream & operator<< (std::ostream &os, Db const &db)
 Outputs the JSON data to an output stream.
 
Value< Dbread_file (fs::path const &path_file_db)
 Deserializes a JSON file into a Db object.
 
Value< void > write_file (fs::path const &path_file_db, Db &db)
 Serializes a Db object and writes it to a JSON file.
 
template<ns_concept::StringRepresentable S>
Value< Dbfrom_string (S &&s)
 Parses a JSON string and creates a Db object.
 

Detailed Description

JSON-based configuration database layer.

Provides type-safe wrapper around nlohmann::json for FlatImage configuration storage and retrieval. Supports both owned and referenced JSON data, enabling flexible ownership semantics. Offers serialization/deserialization, element access, file I/O, and type-safe conversions with integrated error handling through the Value<T> pattern.

Typedef Documentation

◆ KeyType

using ns_db::KeyType = json_t::value_t

Definition at line 50 of file db.hpp.

◆ object_t

using ns_db::object_t = nlohmann::basic_json<>::object_t

Definition at line 32 of file db.hpp.

Function Documentation

◆ from_string()

Value< Db > ns_db::from_string ( S && s)

Parses a JSON string and creates a Db object.

Converts a string representation of JSON data into a Db object. The input must be convertible to std::string (via the StringRepresentable concept). Validates that the string is non-empty before attempting to parse. Uses nlohmann::json::parse() for deserialization. Returns an error if the string is empty or contains invalid JSON.

Template Parameters
SType that can be represented as a string (string_view, const char*, etc.)
Parameters
sThe JSON string data to parse
Returns
Value<Db> The parsed database object on success, or error on parse failure

Definition at line 496 of file db.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<()

std::ostream & ns_db::operator<< ( std::ostream & os,
Db const & db )
inline

Outputs the JSON data to an output stream.

Serializes the underlying nlohmann::json object and writes it to the provided output stream. This enables standard stream operations like std::cout << db. Uses nlohmann::json's built-in stream insertion operator for formatting.

Parameters
osThe target output stream
dbThe database object to print
Returns
std::ostream& Reference to the output stream for chaining

Definition at line 427 of file db.hpp.

◆ read_file()

Value< Db > ns_db::read_file ( fs::path const & path_file_db)
inlinenodiscard

Deserializes a JSON file into a Db object.

Reads a JSON file from the filesystem, parses its contents, and constructs a Db object wrapping the parsed JSON data. Validates that the file exists and can be opened before attempting to parse. Uses nlohmann::json::parse() for deserialization. Returns an error if the file doesn't exist, cannot be opened, or contains invalid JSON.

Parameters
path_file_dbPath to the JSON file to read
Returns
Value<Db> The deserialized Db object on success, or error on file/parse failure

Definition at line 444 of file db.hpp.

Here is the call graph for this function:

◆ write_file()

Value< void > ns_db::write_file ( fs::path const & path_file_db,
Db & db )
inlinenodiscard

Serializes a Db object and writes it to a JSON file.

Converts the Db object's underlying JSON data to a formatted string with 2-space indentation and writes it to the specified file. Opens the file in truncate mode to overwrite any existing content. Closes the file after writing. Returns an error if the file cannot be opened or the JSON cannot be serialized.

Parameters
path_file_dbPath to the target JSON file
dbThe database object to serialize and write
Returns
Value<void> Success indicator, or error on file/serialization failure

Definition at line 474 of file db.hpp.

Here is the call graph for this function: