/* * Copyright (C) 2014 Cloudius Systems, Ltd. */ #ifndef DATABASE_HH_ #define DATABASE_HH_ #include "core/sstring.hh" #include #include #include #include #include #include #include #include #include struct row { std::vector cells; }; using key_compare = std::function; struct partition { row static_columns; // row key within partition -> row std::map rows; }; class data_type { public: // Hide the virtual stuff behind an impl class. This allows us to treat // data_type as a normal value - we can copy, assign, and destroy it // without worrying about the destructor. struct impl { sstring name; impl(sstring name) : name(name) {} virtual ~impl() {} virtual void serialize(const boost::any& value, std::ostream& out) = 0; virtual boost::any deserialize(std::istream& in) = 0; }; private: impl* _impl; public: explicit data_type(impl* impl) : _impl(impl) {} static data_type find(const sstring& name); const sstring& name() const { return _impl->name; } void serialize(const boost::any& value, std::ostream& out) { return _impl->serialize(value, out); } boost::any deserialize(std::istream& in) { return _impl->deserialize(in); } bool operator==(const data_type& x) const { return _impl == x._impl; } bool operator!=(const data_type& x) const { return _impl != x._impl; } }; // FIXME: add missing types extern data_type int_type; extern data_type bigint_type; extern data_type ascii_type; extern data_type blob_type; extern data_type varchar_type; extern data_type text_type; struct column_definition { sstring name; data_type type; }; struct column_family { // primary key = paritition key + clustering_key std::vector partition_key; std::vector clustering_key; std::vector column_defs; std::unordered_map column_names; // partition key -> partition std::map partitions; }; struct keyspace { std::unordered_map column_families; }; struct database { std::unordered_map keyspaces; }; #endif /* DATABASE_HH_ */