Relational Storage API
Overview
The relational storage interfaces and in-memory development implementation are grouped under the Doxygen group StorageAPI.
Core Interfaces
RelationalStorage
-
class RelationalStorage
Storage API for the relational model.
Implementations should validate inputs against the provided TableSchema and return appropriate Status codes using the Result<T> wrapper where applicable.
Error semantics (MVP):
createTable: AlreadyExists when table exists; Ok on success
insertRow: NotFound when table missing; InvalidArgument on schema mismatch; FailedPrecondition on uniqueness constraint violations; Ok on success
select: NotFound when table missing; InvalidArgument when a requested projection column does not exist; Ok with ResultSet on success
Subclassed by kadedb::InMemoryRelationalStorage
Public Functions
-
virtual ~RelationalStorage() = default
-
virtual Status createTable(const std::string &table, const TableSchema &schema) = 0
Create a table with a name and schema.
- Parameters:
table – Table name
schema – TableSchema definition
- Returns:
Status::AlreadyExists if table exists; Status::OK on success
-
virtual Status insertRow(const std::string &table, const Row &row) = 0
Insert a row validated against the table schema.
- Parameters:
table – Table name
row – Row to insert (deep copied by implementation)
- Returns:
Status::NotFound if table missing; Status::InvalidArgument if row fails schema validation; Status::FailedPrecondition if constraints (e.g., unique) would be violated; Status::OK on success
-
virtual Result<ResultSet> select(const std::string &table, const std::vector<std::string> &columns, const std::optional<Predicate> &where = std::nullopt) = 0
Basic SELECT across all rows with optional projection and predicate.
- Parameters:
table – Table name
columns – Projection list; empty means select *
where – Optional Predicate applied to each row
- Returns:
Result<ResultSet>::err(Status::NotFound) if table missing; Result<ResultSet>::err(Status::InvalidArgument) if any requested projection column is unknown; Result<ResultSet>::ok(ResultSet) on success (possibly empty)
-
virtual std::vector<std::string> listTables() const = 0
List existing table names.
- Returns:
Vector of table names; empty if none.
-
virtual Status dropTable(const std::string &table) = 0
Drop a table and its data.
- Parameters:
table – Table name
- Returns:
Status::NotFound if table missing; Status::OK on success
-
virtual Result<size_t> deleteRows(const std::string &table, const std::optional<Predicate> &where = std::nullopt) = 0
Delete rows matching an optional predicate.
- Parameters:
table – Table name
where – Optional Predicate; when not provided, deletes all rows
- Returns:
Result<size_t> count of deleted rows, or Status::NotFound if table missing
-
virtual Status updateRows(const std::string &table, const std::unordered_map<std::string, std::unique_ptr<Value>> &assignments, const std::optional<Predicate> &where = std::nullopt) = 0
Update rows by assigning new values to specified columns, for rows matching an optional predicate.
- Parameters:
table – Table name
assignments – Map column -> Value (cloned by implementation)
where – Optional Predicate; when not provided, updates all rows
- Returns:
Status::NotFound if table missing; Status::InvalidArgument for unknown columns or type/constraint violations; Status::FailedPrecondition for post-update uniqueness violations; Status::OK on success
-
virtual Status truncateTable(const std::string &table) = 0
Truncate a table (delete all rows) without dropping schema.
- Parameters:
table – Table name
- Returns:
Status::NotFound if table missing; Status::OK on success
In-Memory Implementation
InMemoryRelationalStorage
-
class InMemoryRelationalStorage : public kadedb::RelationalStorage
Public Functions
-
InMemoryRelationalStorage() = default
-
~InMemoryRelationalStorage() override = default
-
virtual Status createTable(const std::string &table, const TableSchema &schema) override
Create a table with a name and schema.
- Parameters:
table – Table name
schema – TableSchema definition
- Returns:
Status::AlreadyExists if table exists; Status::OK on success
-
virtual Status insertRow(const std::string &table, const Row &row) override
Insert a row validated against the table schema.
- Parameters:
table – Table name
row – Row to insert (deep copied by implementation)
- Returns:
Status::NotFound if table missing; Status::InvalidArgument if row fails schema validation; Status::FailedPrecondition if constraints (e.g., unique) would be violated; Status::OK on success
-
virtual Result<ResultSet> select(const std::string &table, const std::vector<std::string> &columns, const std::optional<Predicate> &where) override
Basic SELECT across all rows with optional projection and predicate.
- Parameters:
table – Table name
columns – Projection list; empty means select *
where – Optional Predicate applied to each row
- Returns:
Result<ResultSet>::err(Status::NotFound) if table missing; Result<ResultSet>::err(Status::InvalidArgument) if any requested projection column is unknown; Result<ResultSet>::ok(ResultSet) on success (possibly empty)
-
virtual std::vector<std::string> listTables() const override
List existing table names.
- Returns:
Vector of table names; empty if none.
-
virtual Status dropTable(const std::string &table) override
Drop a table and its data.
- Parameters:
table – Table name
- Returns:
Status::NotFound if table missing; Status::OK on success
-
virtual Result<size_t> deleteRows(const std::string &table, const std::optional<Predicate> &where) override
Delete rows matching an optional predicate.
- Parameters:
table – Table name
where – Optional Predicate; when not provided, deletes all rows
- Returns:
Result<size_t> count of deleted rows, or Status::NotFound if table missing
-
virtual Status updateRows(const std::string &table, const std::unordered_map<std::string, std::unique_ptr<Value>> &assignments, const std::optional<Predicate> &where) override
Update rows by assigning new values to specified columns, for rows matching an optional predicate.
- Parameters:
table – Table name
assignments – Map column -> Value (cloned by implementation)
where – Optional Predicate; when not provided, updates all rows
- Returns:
Status::NotFound if table missing; Status::InvalidArgument for unknown columns or type/constraint violations; Status::FailedPrecondition for post-update uniqueness violations; Status::OK on success
-
virtual Status truncateTable(const std::string &table) override
Truncate a table (delete all rows) without dropping schema.
- Parameters:
table – Table name
- Returns:
Status::NotFound if table missing; Status::OK on success
-
InMemoryRelationalStorage() = default