9 , storage_engine_{path()} {
14 tag_columns_ = tag_columns;
19 if (been_populated()) {
20 throw std::runtime_error{
21 "Table::addTagColumn(): Table '" + name_
22 +
"' has previously been populated with data."
25 auto inserted{tag_columns_.insert(tag_column).second};
27 throw std::runtime_error{
28 "Table::addTagColumn(): Tag column '" + tag_column
29 +
"' already exists in '" + name_ +
"'."
37 if (been_populated()) {
38 throw std::runtime_error{
39 "Table::removeTagColumn(): Table '" + name_
40 +
"' has previously been populated with data."
43 auto removed{tag_columns_.erase(tag_column) > 0};
45 throw std::runtime_error{
46 "Table::removeTagColumn(): Tag column '" + tag_column
47 +
"' does not exist in '" + name_ +
"'."
55 std::filesystem::remove_all(
path());
56 std::filesystem::create_directories(
path());
72 return db_path_ / FilePath{name_};
75bool Table::been_populated() const noexcept {
76 return !storage_engine_.
empty();
79void Table::save_tag_columns()
const {
80 std::ofstream file{tag_columns_path()};
81 if (!file.is_open()) {
82 throw std::runtime_error{
83 "Table::save_tag_columns(): Unable to open file "
84 + std::string(tag_columns_path()) +
"."
87 for (
const auto& column : tag_columns_) {
88 file << column <<
"\n";
93void Table::load_tag_columns() {
95 if (!std::filesystem::exists(tag_columns_path())) {
98 std::ifstream file{tag_columns_path()};
99 if (!file.is_open()) {
100 throw std::runtime_error{
101 "Table::load_tag_columns(): Unable to open file "
102 + std::string(tag_columns_path()) +
"."
106 while (std::getline(file, column)) {
107 if (!column.empty()) {
108 tag_columns_.insert(column);
114FilePath Table::tag_columns_path() const noexcept {
115 return path() / TAG_COLUMNS_FILENAME;
119 std::filesystem::create_directories(
path());
Friendly query builder for querying a Table.
void replayWAL()
Replay the write-ahead log.
bool empty() const noexcept
Check if the LSM tree is empty.
Represents a table in vkdb.
void clear() const noexcept
Clear the table.
Table & addTagColumn(const TagKey &tag_column)
Add a tag column.
TableName name() const noexcept
Get the name of the table.
Table & setTagColumns(const TagColumns &tag_columns) noexcept
Set the TagColumns object.
TagColumns tagColumns() const noexcept
Get the TagColumns object.
FilePath path() const noexcept
Get the path to the table directory.
FriendlyQueryBuilder< double > query() noexcept
Get a FriendlyQueryBuilder object.
Table & removeTagColumn(const TagKey &tag_column)
Remove a tag column.
Table()=delete
Deleted default constructor.