Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Writable_Database.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2//
3// This code was automatically generated by the joedb compiler
4// https://www.joedb.org/
5//
6// Path to compiler: /home/rcoulom/repos/joedb/compcmake/gcc_debug/joedbc
7// Version: 9.5.0
8// joedbc compilation time: May 5 2025 19:51:43
9// Generation of this file: 2025-05-05 17:51:47 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#ifndef joedb_db_encoded_file_Writable_Database_declared
13#define joedb_db_encoded_file_Writable_Database_declared
14
15#include "Database.h"
16#include "joedb/Span.h"
17
19{
20 namespace detail
21 {
22 class Client_Data;
23 }
24
25 class Client;
26 class Multiplexer;
27
28 /// A writable @ref Database constructed from a writable @ref joedb::Buffered_File
30 {
31 friend class detail::Client_Data;
32 friend class Client;
33 friend class Multiplexer;
34
35 private:
37 bool ready_to_write;
38
39 void play_journal();
40 void auto_upgrade();
41 void check_single_row();
42
43 void initialize()
44 {
45 play_journal();
47 auto_upgrade();
48 check_single_row();
49 }
50
52 (
54 bool perform_initialization
55 );
56
57 public:
59
60 const joedb::Readonly_Journal &get_journal() const {return journal;}
61
62 std::string read_blob(joedb::Blob blob) const
63 {
64 return journal.get_file().read_blob(blob);
65 }
66
67 joedb::Blob write_blob(const std::string &data) final
68 {
69 return journal.write_blob(data);
70 }
71
72 int64_t ahead_of_checkpoint() const
73 {
74 return journal.ahead_of_checkpoint();
75 }
76
78 {
79 journal.soft_checkpoint();
80 }
81
83 {
84 journal.hard_checkpoint();
85 }
86
87 void write_comment(const std::string &comment);
88 void write_timestamp();
89 void write_timestamp(int64_t timestamp);
90 void write_valid_data();
91 void flush() override {journal.flush();}
92
93 void clear_buffer_table();
94
96 {
97 id_of_buffer result(Record_Id(storage_of_buffer.freedom_keeper.get_free_record() - 1));
98 storage_of_buffer.resize(storage_of_buffer.freedom_keeper.size());
100
101 journal.insert_into(Table_Id(1), result.get_record_id());
102 return result;
103 }
104
106 {
107 id_of_buffer result(Record_Id(storage_of_buffer.size() + 1));
108 storage_of_buffer.resize(storage_of_buffer.size() + size);
110 journal.insert_vector(Table_Id(1), result.get_record_id(), size);
111 return result;
112 }
113
115 (
116 joedb::Blob field_value_of_data,
117 int64_t field_value_of_size,
118 int64_t field_value_of_offset
119 )
120 {
121 auto result = new_buffer();
122 set_data(result, field_value_of_data);
123 set_size(result, field_value_of_size);
124 set_offset(result, field_value_of_offset);
125 return result;
126 }
127
129 {
131 journal.delete_from(Table_Id(1), record.get_record_id());
132 }
133
135 {
136 for (size_t i = size; i > 0;)
137 internal_delete_buffer(v[--i].get_record_id());
138 journal.delete_vector(Table_Id(1), v.get_record_id(), size);
139 }
140
141 void set_data(id_of_buffer record, joedb::Blob field_value_of_data)
142 {
143 internal_update_buffer__data(record.get_record_id(), field_value_of_data);
144 journal.update_blob(Table_Id(1), record.get_record_id(), Field_Id(1), field_value_of_data);
145 }
146
147 template<typename F> void update_vector_of_data(id_of_buffer record, size_t size, F f)
148 {
149 std::exception_ptr exception;
150 joedb::Span<joedb::Blob> span(&storage_of_buffer.field_value_of_data[record.get_id() - 1], size);
151 try {f(span);}
152 catch (...) {exception = std::current_exception();}
154 journal.update_vector_blob(Table_Id(1), record.get_record_id(), Field_Id(1), size, (span.begin()));
155 if (exception)
156 std::rethrow_exception(exception);
157 }
158
159 void set_size(id_of_buffer record, int64_t field_value_of_size)
160 {
161 internal_update_buffer__size(record.get_record_id(), field_value_of_size);
162 journal.update_int64(Table_Id(1), record.get_record_id(), Field_Id(2), field_value_of_size);
163 }
164
165 template<typename F> void update_vector_of_size(id_of_buffer record, size_t size, F f)
166 {
167 std::exception_ptr exception;
168 joedb::Span<int64_t> span(&storage_of_buffer.field_value_of_size[record.get_id() - 1], size);
169 try {f(span);}
170 catch (...) {exception = std::current_exception();}
172 journal.update_vector_int64(Table_Id(1), record.get_record_id(), Field_Id(2), size, (span.begin()));
173 if (exception)
174 std::rethrow_exception(exception);
175 }
176
177 void set_offset(id_of_buffer record, int64_t field_value_of_offset)
178 {
179 internal_update_buffer__offset(record.get_record_id(), field_value_of_offset);
180 journal.update_int64(Table_Id(1), record.get_record_id(), Field_Id(3), field_value_of_offset);
181 }
182
183 template<typename F> void update_vector_of_offset(id_of_buffer record, size_t size, F f)
184 {
185 std::exception_ptr exception;
186 joedb::Span<int64_t> span(&storage_of_buffer.field_value_of_offset[record.get_id() - 1], size);
187 try {f(span);}
188 catch (...) {exception = std::current_exception();}
190 journal.update_vector_int64(Table_Id(1), record.get_record_id(), Field_Id(3), size, (span.begin()));
191 if (exception)
192 std::rethrow_exception(exception);
193 }
194
195
196 };}
197
198#endif
const Buffered_File & get_file() const
T * begin()
Definition Span.h:39
void delete_vector(Table_Id table_id, Record_Id record_id, size_t size) final
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) final
int64_t ahead_of_checkpoint() const noexcept
Blob write_blob(const std::string &data) final
void delete_from(Table_Id table_id, Record_Id record_id) final
void insert_into(Table_Id table_id, Record_Id record_id) final
void hard_checkpoint()
Definition Writable.h:22
void soft_checkpoint()
Definition Writable.h:21
Handle concurrent access to a joedb::Buffered_File using a joedb::Connection.
Definition Client.h:39
Store all the tables of the database.
Definition Database.h:75
void internal_delete_buffer(Record_Id record_id)
Definition Database.h:101
void internal_update_buffer__size(Record_Id record_id, int64_t field_value_of_size)
Definition Database.h:145
void internal_update_vector_buffer__data(Record_Id record_id, size_t size, const joedb::Blob *value)
Definition Database.h:131
detail::data_of_buffer storage_of_buffer
Definition Database.h:98
void internal_insert_buffer(Record_Id record_id)
Definition Database.h:110
void timestamp(int64_t timestamp) override
Definition Database.h:376
void internal_update_buffer__offset(Record_Id record_id, int64_t field_value_of_offset)
Definition Database.h:169
void internal_update_buffer__data(Record_Id record_id, joedb::Blob field_value_of_data)
Definition Database.h:121
void internal_update_vector_buffer__offset(Record_Id record_id, size_t size, const int64_t *value)
Definition Database.h:179
void comment(const std::string &comment) override
Definition Database.h:375
void internal_vector_insert_buffer(Record_Id record_id, size_t size)
Definition Database.h:115
void internal_update_vector_buffer__size(Record_Id record_id, size_t size, const int64_t *value)
Definition Database.h:155
Write simultaneously to the database and the file (ignore schema changes)
Definition Multiplexer.h:40
A writable Database constructed from a writable joedb::Buffered_File.
joedb::Blob write_blob(const std::string &data) final
void set_data(id_of_buffer record, joedb::Blob field_value_of_data)
std::string read_blob(joedb::Blob blob) const
void update_vector_of_size(id_of_buffer record, size_t size, F f)
void delete_vector_of_buffer(id_of_buffer v, size_t size)
void set_size(id_of_buffer record, int64_t field_value_of_size)
void update_vector_of_data(id_of_buffer record, size_t size, F f)
void set_offset(id_of_buffer record, int64_t field_value_of_offset)
void write_comment(const std::string &comment)
const joedb::Readonly_Journal & get_journal() const
id_of_buffer new_buffer(joedb::Blob field_value_of_data, int64_t field_value_of_size, int64_t field_value_of_offset)
void update_vector_of_offset(id_of_buffer record, size_t size, F f)
Strongly-typed wrapper around an integer representing a row of the buffer table.
Definition ids.h:25
constexpr Record_Id get_record_id() const
Definition ids.h:36
constexpr auto get_id() const
Definition ids.h:35
Automatically generated by joedbc.
Definition Client.h:19