12 const std::string &name
17 throw Exception(std::string(message) +
": invalid identifier: " + name);
38 const auto it = tables.find(table_id);
40 if (it == tables.end())
44 "get_table: invalid table_id: " + std::to_string(
to_underlying(table_id))
58 return get_table(table_id).field_names;
69 static Type null_type;
70 const auto table_it = tables.find(table_id);
71 if (table_it == tables.end())
73 const auto &fields = table_it->second.get_fields();
74 const auto field_it = fields.find(field_id);
75 if (field_it == fields.end())
77 return field_it->second.get_type();
87 return get_table(table_id).freedom;
90 #define TYPE_MACRO(type, return_type, type_id, R, W)\
91 const type &Database_Schema::get_##type_id\
98 return *get_table(table_id).get_own_##type_id##_storage(record_id, field_id);\
109 throw Exception(
"create_table: name already used: " + name);
120 const auto it =
tables.find(table_id);
122 throw Exception(
"drop_table: invalid table_id");
132 const std::string &name
135 check_identifier(
"rename_table", name);
137 if (find_table(name) !=
Table_Id(0))
138 throw Exception(
"rename_table: name already used: " + name);
142 table_names[table_id] = name;
150 const std::string &name,
154 check_identifier(
"add_field", name);
156 get_table(table_id).add_field(name, type);
172 const std::string &name
175 check_identifier(
"rename_field", name);
177 Table &table = get_table(table_id);
179 auto &field_names = table.field_names;
180 const auto field_it = field_names.find(field_id);
181 if (field_it == field_names.end())
182 throw Exception(
"rename_field: invalid field_id");
185 throw Exception(
"rename_field: name already used: " + name);
187 field_it->second = name;
std::map< Table_Id, std::string > table_names
void create_table(const std::string &name) override
const Table & get_table(Table_Id table_id) const
static void check_identifier(const char *message, const std::string &name)
virtual ~Database_Schema() override
void drop_table(Table_Id table_id) override
void add_field(Table_Id table_id, const std::string &name, Type type) override
const Compact_Freedom_Keeper & get_freedom(Table_Id table_id) const override
void rename_field(Table_Id, Field_Id, const std::string &name) override
void rename_table(Table_Id table_id, const std::string &name) override
void drop_field(Table_Id table_id, Field_Id field_id) override
Table_Id current_table_id
std::map< Table_Id, Table > tables
const Type & get_field_type(Table_Id table_id, Field_Id field_id) const override
const std::map< Field_Id, std::string > & get_fields(Table_Id table_id) const override
Table_Id find_table(const std::string &name) const
void drop_field(Field_Id field_id)
Field_Id find_field(const std::string &name) const
constexpr std::underlying_type< Table_Id >::type to_underlying(Table_Id id)
bool is_identifier(const std::string &s)