usql update
This commit is contained in:
61
usql/table.h
61
usql/table.h
@@ -1,14 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "index.h"
|
||||
#include "parser.h"
|
||||
#include "row.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace usql {
|
||||
|
||||
struct Table {
|
||||
|
||||
struct Table {
|
||||
Table(const Table &other);
|
||||
Table(const std::string& name, const std::vector<ColDefNode>& columns);
|
||||
|
||||
@@ -18,13 +20,15 @@ namespace usql {
|
||||
[[nodiscard]] int columns_count() const { return (int) m_col_defs.size(); };
|
||||
[[nodiscard]] size_t rows_count() const { return m_rows.size(); };
|
||||
|
||||
Row& create_empty_row();
|
||||
void commit_row(const Row &row);
|
||||
void commit_copy_of_row(const Row &row);
|
||||
[[nodiscard]] size_t get_rowid(const Row &row) const;
|
||||
|
||||
Row &create_empty_row();
|
||||
void commit_row(Row &row);
|
||||
void commit_copy_of_row(Row &row);
|
||||
|
||||
static void validate_column(const ColDefNode *col_def, ValueNode *col_val);
|
||||
static void validate_column(const ColDefNode *col_def, ColValue &col_val);
|
||||
void validate_row(const Row &row);
|
||||
void validate_row(Row &row);
|
||||
|
||||
std::string csv_string();
|
||||
int load_csv_string(const std::string &content);
|
||||
@@ -32,14 +36,45 @@ namespace usql {
|
||||
|
||||
void print();
|
||||
|
||||
std::string m_name;
|
||||
std::string m_name;
|
||||
std::vector<ColDefNode> m_col_defs;
|
||||
std::vector<Row> m_rows;
|
||||
|
||||
static long string_to_long(const std::string &s) ;
|
||||
static double string_to_double(const std::string &s) ;
|
||||
std::vector<Row> m_rows;
|
||||
std::vector<Index> m_indexes;
|
||||
|
||||
void create_row_from_vector(const std::vector<ColDefNode> &colDefs, const std::vector<std::string> &csv_line);
|
||||
};
|
||||
|
||||
}
|
||||
void create_index(const Index& index);
|
||||
bool drop_index(const std::string &index_name);
|
||||
|
||||
static void index_row(Index &index, const ColDefNode &col_def, const Row &row, size_t rowid);
|
||||
static void unindex_row(Index &index, const ColDefNode &col_def, const Row &row, size_t rowid);
|
||||
static void reindex_row(Index &index, const ColDefNode &col_def, const Row &old_row, const Row &new_row, size_t rowid);
|
||||
|
||||
void index_row(const Row &row);
|
||||
void unindex_row(const Row &row);
|
||||
void reindex_row(const Row &old_row, const Row &new_row);
|
||||
|
||||
void index_rows(const std::string &index_name);
|
||||
|
||||
Index * get_index(const std::string &index_name);
|
||||
Index * get_index_for_column(const std::string &col_name);
|
||||
|
||||
bool empty();
|
||||
|
||||
struct rows_scanner {
|
||||
explicit rows_scanner(Table *tbl) : m_use_rowids(false), m_table(tbl), m_fscan_itr(tbl->m_rows.begin()) {}
|
||||
rows_scanner(Table *tbl, std::vector<rowid_t> rowids) : m_use_rowids(true), m_table(tbl), m_rowids(std::move(rowids)), m_rowids_idx(0) {}
|
||||
|
||||
Row *next();
|
||||
|
||||
private:
|
||||
bool m_use_rowids;
|
||||
Table * m_table;
|
||||
std::vector<Row>::iterator m_fscan_itr;
|
||||
std::vector<rowid_t> m_rowids;
|
||||
size_t m_rowids_idx{};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user