#pragma once #include #include namespace Poco { namespace Util { class AbstractConfiguration; } } namespace DB { /** * Class to represent arbitrary-structured named collection object. * It can be defined via config or via SQL command. * * * ... * * ... * */ class NamedCollection { public: using Key = std::string; using Keys = std::set>; enum class SourceId : uint8_t { NONE = 0, CONFIG = 1, SQL = 2, }; static MutableNamedCollectionPtr create( const Poco::Util::AbstractConfiguration & config, const std::string & collection_name, const std::string & collection_path, const Keys & keys, SourceId source_id_, bool is_mutable_); bool has(const Key & key) const; bool hasAny(const std::initializer_list & keys) const; template T get(const Key & key) const; template T getOrDefault(const Key & key, const T & default_value) const; template T getAny(const std::initializer_list & keys) const; template T getAnyOrDefault(const std::initializer_list & keys, const T & default_value) const; std::unique_lock lock(); template void set(const Key & key, const T & value, std::optional is_overridable); template void setOrUpdate(const Key & key, const T & value, std::optional is_overridable); bool isOverridable(const Key & key, bool default_value) const; template void remove(const Key & key); MutableNamedCollectionPtr duplicate() const; Keys getKeys(ssize_t depth = -1, const std::string & prefix = "") const; using iterator = typename Keys::iterator; using const_iterator = typename Keys::const_iterator; template const_iterator begin() const; template const_iterator end() const; std::string dumpStructure() const; bool isMutable() const { return is_mutable; } SourceId getSourceId() const { return source_id; } private: class Impl; using ImplPtr = std::unique_ptr; NamedCollection( ImplPtr pimpl_, const std::string & collection_name, SourceId source_id, bool is_mutable); void assertMutable() const; ImplPtr pimpl; const std::string collection_name; const SourceId source_id; const bool is_mutable; mutable std::mutex mutex; }; }