C++ · Quickstart

Quickstart

#include <ustore/db.hpp>#include <ustore/ranges.hpp> 1.0.0-rc.1 · d6d40961

§ Conventions

Everything lives in unum::ustore, and #include <ustore/ustore.hpp> brings in all of it. Fallible calls return a status_t, a status_code_t beside a static message, or an expected that holds either a value or the status_t explaining its absence; both are [[nodiscard]]. Dereferencing an expected<value_type> yields the value_type, and auto [value, status] decomposes one whose value is default constructible. key_from_integer spells a non-negative integer as a key, and key_after answers the key right after another. Nothing copies values out of the arena, and nothing throws.

using namespace unum::ustore;

auto [db, status] = database_t::init_ram();
if (status.failed())
    std::fprintf(stderr, "%s\n", status.message);

database_t::init_ram, open_ram, open_rocksdb, view_rocksdb, open_leveldb and open_nvme wrap the C opens of the same names, taking their argument structs as options.

API

Classdatabase_ref_tThe head of a database as a map from collection names to collections, as the calls on one executor see it, without owning either.19
db.hpp:771 ↗
class database_ref_t
database_ref_t
db.hpp:781 ↗
database_ref_t() noexcept=default;
database_ref_t(receiver_t receiver) noexcept;
operator ustore_database_tThe C handle of the database, so the reference passes as a ustore_database_t.
db.hpp:785 ↗
operator ustore_database_t() const noexcept;
receiverThe database and executor this reference runs on, to build another reference on them.
db.hpp:788 ↗
receiver_t receiver() const noexcept;
onThe same head, running every call on executor.
db.hpp:791 ↗
database_ref_t on(ustore_executor_t executor) const noexcept;
deferredThe same head, whose verbs submit to executor and answer deferred calls.
db.hpp:794 ↗
deferred_database_t deferred(ustore_executor_t executor) const noexcept;
describeReports the engine of the database, what it supports and how much it holds.
db.hpp:799 ↗
expected<ustore_database_description_t> describe() noexcept;
supports_transactionsWhether the engine runs transactions.
db.hpp:813 ↗
bool supports_transactions() noexcept;
transactionBegins a transaction, which runs its calls on this receiver's executor.
db.hpp:817 ↗
expected<transaction_t> transaction() noexcept;
snapshotPins a point-in-time view of the database, which the returned snapshot frees when it goes.
db.hpp:820 ↗
expected<snapshot_t> snapshot() noexcept;
operator[]Finds the collection named name, or creates it when absent.
db.hpp:823 ↗
expected<blobs_collection_t> operator[](std::string_view name) noexcept;
containsWhether a collection named name exists at the head.
db.hpp:826 ↗
expected<bool> contains(std::string_view name) noexcept;
collectionsLists the collections at the head, with their identifiers in arena.
db.hpp:829 ↗
expected<collections_list_t> collections(arena_t & arena) noexcept;
createCreates a collection holding the modality of collection_type_ under name, which no other collection may carry.
db.hpp:834 ↗
template <typename collection_type_ = blobs_collection_t>
expected<collection_type_> create(std::string_view name) noexcept;
findThe collection named name, refusing one that holds another modality than collection_type_.
db.hpp:859 ↗
template <typename collection_type_ = blobs_collection_t>
expected<collection_type_> find(std::string_view name) noexcept;

Statuses

  • status_code_t::not_found_k No collection carries name.
  • status_code_t::invalid_argument_k The collection holds another modality than collection_type_.
find_or_createThe collection named name, created when no collection carries the name.
db.hpp:867 ↗
template <typename collection_type_ = blobs_collection_t>
expected<collection_type_> find_or_create(
    std::string_view name) noexcept;
dropDrops the collection name addresses, which takes the name with it.
db.hpp:874 ↗
status_t drop(std::string_view name) noexcept;
clearEmpties every collection at once, as mode names.
db.hpp:896 ↗
status_t clear(ustore_drop_mode_t mode) noexcept;

Statuses

  • status_code_t::invalid_argument_k The RAM and RocksDB engines refuse to drop the collections while a snapshot is open.
compactReclaims the space overwritten and removed data still takes, one collection at a time, reporting its advance to progress, which may cancel it between collections.
db.hpp:909 ↗
status_t compact(progress_arg_t progress = {}) noexcept;
flushMakes every commit that returned before this call durable, as if each had asked for ustore_durability_flushed_k.
db.hpp:923 ↗
status_t flush() noexcept;
Classdatabase_tA database as a transactional map from collection names to collections of binary values, which owns its handle.10
db.hpp:937 ↗
class database_t

It is thread-safe except for the opens and close, never copies, and outlives the collections it hands out, while its transactions and snapshots may outlive it.

database_t
db.hpp:955 ↗
database_t() noexcept=default;
database_t(database_t const &)=delete;
database_t(database_t && other) noexcept;
database_t(ustore_database_t adopted) noexcept;
operator=
db.hpp:957 ↗
database_t & operator=(database_t const &)=delete;
database_t & operator=(database_t && other) noexcept;
closeDrops this handle, closing the database once no transaction or snapshot of it holds it open.
db.hpp:1007 ↗
void close() noexcept;
~database_t
db.hpp:1012 ↗
~database_t() noexcept;
init_ramStarts an empty database of the in-memory engine blocking on executor, or on the calling thread without one.
db.hpp:967 ↗
expected<database_t> init_ram(
    ustore_database_init_ram_t options = {},
    ustore_executor_t executor = nullptr) noexcept;

The database runs its own calls on the calling thread until a receiver names an executor.

open_ramServes the directory options name through the in-memory engine, which persists there as one image, blocking on executor, or on the calling thread without one.
db.hpp:974 ↗
expected<database_t> open_ram(
    ustore_database_open_ram_t options,
    ustore_executor_t executor = nullptr) noexcept;
open_rocksdbServes the directory options name through the RocksDB engine, blocking on executor, or on the calling thread without one.
db.hpp:981 ↗
expected<database_t> open_rocksdb(
    ustore_database_open_rocksdb_t options,
    ustore_executor_t executor = nullptr) noexcept;
view_rocksdbServes the directory options name through the RocksDB engine, read-only, blocking on executor, or on the calling thread without one.
db.hpp:988 ↗
expected<database_t> view_rocksdb(
    ustore_database_view_rocksdb_t options,
    ustore_executor_t executor = nullptr) noexcept;
open_leveldbServes the directory options name through the LevelDB engine, blocking on executor, or on the calling thread without one.
db.hpp:995 ↗
expected<database_t> open_leveldb(
    ustore_database_open_leveldb_t options,
    ustore_executor_t executor = nullptr) noexcept;
open_nvmeServes the directories options name through the NVMe engine on the calling thread, lending it the executor they name until close.
db.hpp:1002 ↗
expected<database_t> open_nvme(
    ustore_database_open_nvme_t options) noexcept;

Functions

bytes_ofThe bytes text spells as an element of a batch, where a missing value and a null string spell empty ones.
ranges.hpp:613 ↗
template <string_like_concept text_type_>
ustore_bytes_view_t bytes_of(text_type_ const & text) noexcept;