12#ifndef joedb_db_encoded_file_Database_declared
13#define joedb_db_encoded_file_Database_declared
45 extern const char * schema_string;
46 inline constexpr size_t schema_string_size = 75;
48 class container_of_buffer;
54 std::vector<joedb::Blob> field_value_of_data;
55 std::vector<int64_t> field_value_of_size;
56 std::vector<int64_t> field_value_of_offset;
60 size_t size()
const {
return freedom_keeper.
size();}
62 void resize(
size_t new_size)
64 field_value_of_data.resize(new_size);
65 field_value_of_size.resize(new_size);
66 field_value_of_offset.resize(new_size);
67 freedom_keeper.
resize(new_size);
81 template<
typename E = joedb::Exception>
84 throw E(
"joedb::db::encoded_file: " + message);
127 storage_of_buffer.field_value_of_data[size_t(record_id) - 1] = field_value_of_data;
137 for (
size_t i = 0; i < size; i++)
141 std::copy_n(value, size, target);
147 int64_t field_value_of_size
151 storage_of_buffer.field_value_of_size[size_t(record_id) - 1] = field_value_of_size;
161 for (
size_t i = 0; i < size; i++)
165 std::copy_n(value, size, target);
171 int64_t field_value_of_offset
175 storage_of_buffer.field_value_of_offset[size_t(record_id) - 1] = field_value_of_offset;
185 for (
size_t i = 0; i < size; i++)
187 int64_t *target = &
storage_of_buffer.field_value_of_offset[size_t(record_id) - 1];
189 std::copy_n(value, size, target);
223 size_t(record_id) <= 0 ||
395 schema_file_size < pos ||
396 schema_file_size > detail::schema_string_size ||
400 detail::schema_string + pos,
401 schema_file_size - pos
425 const std::string &name
435 const std::string &name,
453 const std::string &name
460 void custom(
const std::string &name)
override
486 throw_exception<joedb::Out_Of_Date>(
"Schema is out of date. Can't upgrade a read-only database.");
507 template<
class Comparator>
508 std::vector<id_of_buffer>
sorted_buffer(Comparator comparator)
const;
549 iterator(
const detail::data_of_buffer &data): fk(&data.freedom_keeper), index(0) {}
582 template<
class Comparator>
585 std::vector<id_of_buffer> result;
587 result.emplace_back(x);
588 std::sort(result.begin(), result.end(), comparator);
ptrdiff_t get_previous(ptrdiff_t index) const override
void resize(ptrdiff_t new_size) override
ptrdiff_t size() const override
ptrdiff_t get_next(ptrdiff_t index) const override
void replay_log(Writable &writable)
int64_t get_checkpoint() const
void rename_field(Table_Id table_id, Field_Id field_id, const std::string &name) final
void create_table(const std::string &name) final
void drop_field(Table_Id table_id, Field_Id field_id) final
void custom(const std::string &name) final
void rename_table(Table_Id table_id, const std::string &name) final
void add_field(Table_Id table_id, const std::string &name, Type type) final
void drop_table(Table_Id table_id) final
Store all the tables of the database.
joedb::Writable_Journal schema_journal
void internal_delete_buffer(Record_Id record_id)
void initialize_with_readonly_journal(joedb::Readonly_Journal &journal)
container_of_buffer get_buffer_table() const
joedb::Blob * get_own_blob_storage(Table_Id table_id, Record_Id record_id, Field_Id field_id, size_t &capacity) final
void internal_update_buffer__size(Record_Id record_id, int64_t field_value_of_size)
int64_t get_size(id_of_buffer record) const
bool is_valid(id_of_buffer id) const
static void throw_exception(const std::string &message)
void insert_into(Table_Id table_id, Record_Id record_id) final
void update_int64(Table_Id table_id, Record_Id record_id, Field_Id field_id, int64_t value) final
void update_blob(Table_Id table_id, Record_Id record_id, Field_Id field_id, joedb::Blob value) final
joedb::Blob get_data(id_of_buffer record) const
int64_t * get_own_int64_storage(Table_Id table_id, Record_Id record_id, Field_Id field_id, size_t &capacity) final
void internal_update_vector_buffer__data(Record_Id record_id, size_t size, const joedb::Blob *value)
void drop_field(Table_Id table_id, Field_Id field_id) final
void update_vector_int64(Table_Id table_id, Record_Id record_id, Field_Id field_id, size_t size, const int64_t *value) final
int64_t get_schema_checkpoint() const
void add_field(Table_Id table_id, const std::string &name, joedb::Type type) override
friend class id_of_buffer
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) final
detail::data_of_buffer storage_of_buffer
Table_Id current_table_id
id_of_buffer next(id_of_buffer id) const
void internal_insert_buffer(Record_Id record_id)
void timestamp(int64_t timestamp) override
void internal_update_buffer__offset(Record_Id record_id, int64_t field_value_of_offset)
bool requires_schema_upgrade() const
void rename_field(Table_Id table_id, Field_Id field_id, const std::string &name) final
void delete_from(Table_Id table_id, Record_Id record_id) final
void internal_update_buffer__data(Record_Id record_id, joedb::Blob field_value_of_data)
joedb::Memory_File schema_file
static id_of_buffer null_buffer()
void set_max_record_id(size_t record_id)
bool is_valid_record_id_for_buffer(Record_Id record_id) const
void custom(const std::string &name) override
id_of_buffer previous(id_of_buffer id) const
void update_vector_blob(Table_Id table_id, Record_Id record_id, Field_Id field_id, size_t size, const joedb::Blob *value) final
std::vector< id_of_buffer > sorted_buffer(Comparator comparator) const
void internal_update_vector_buffer__offset(Record_Id record_id, size_t size, const int64_t *value)
void create_table(const std::string &name) override
void rename_table(Table_Id table_id, const std::string &name) final
friend class container_of_buffer
void comment(const std::string &comment) override
void internal_vector_insert_buffer(Record_Id record_id, size_t size)
void drop_table(Table_Id table_id) final
int64_t get_offset(id_of_buffer record) const
void internal_update_vector_buffer__size(Record_Id record_id, size_t size, const int64_t *value)
Implement the joedb::Readable interface for a compiled database.
bool operator==(const iterator &i) const
std::forward_iterator_tag iterator_category
std::ptrdiff_t difference_type
id_of_buffer operator*() const
bool operator!=(const iterator &i) const
returned by Database::get_buffer_table
id_of_buffer get_end() const
id_of_buffer last() const
id_of_buffer first() const
static id_of_buffer get_at(size_t i)
bool is_valid_at(size_t i)
Strongly-typed wrapper around an integer representing a row of the buffer table.
constexpr Record_Id get_record_id() const
constexpr auto get_id() const
#define JOEDB_DEBUG_ASSERT(x)
constexpr const char * get_version()
Automatically generated by joedbc.