Joedb 9.1.4
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/doc/source/tutorial/build/joedbc
7// Version: 9.1.4
8// joedbc compilation time: Apr 15 2025 14:46:29
9// Generation of this file: 2025-04-15 12:46:31 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#ifndef tutorial_Writable_Database_declared
13#define tutorial_Writable_Database_declared
14
15#include "Database.h"
16#include "joedb/Span.h"
17
18namespace tutorial
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();
50 }
51
53 (
55 bool perform_initialization,
57 joedb::Commit_Level commit_level
58 );
59
60 public:
62 (
66 );
67
68 const joedb::Readonly_Journal &get_journal() const {return journal;}
69
70 std::string read_blob_data(joedb::Blob blob) const
71 {
72 return journal.get_file().read_blob_data(blob);
73 }
74
75 joedb::Blob write_blob_data(const std::string &data) final
76 {
77 return journal.write_blob_data(data);
78 }
79
80 int64_t ahead_of_checkpoint() const
81 {
82 return journal.ahead_of_checkpoint();
83 }
84
89
94
99
101 {
102 journal.default_checkpoint();
103 }
104
105 void checkpoint(joedb::Commit_Level commit_level) final
106 {
107 journal.checkpoint(commit_level);
108 }
109
110 void write_comment(const std::string &comment);
111 void write_timestamp();
112 void write_timestamp(int64_t timestamp);
113 void write_valid_data();
114 void flush() override {journal.flush();}
115
116 void clear_city_table();
117
119 {
120 id_of_city result(Record_Id(storage_of_city.freedom_keeper.get_free_record() - 1));
121 storage_of_city.resize(storage_of_city.freedom_keeper.size());
123
124 journal.insert_into(Table_Id(1), result.get_record_id());
125 return result;
126 }
127
129 {
130 id_of_city result(Record_Id(storage_of_city.size() + 1));
131 storage_of_city.resize(storage_of_city.size() + size);
133 journal.insert_vector(Table_Id(1), result.get_record_id(), size);
134 return result;
135 }
136
138 (
139 const std::string& field_value_of_name
140 )
141 {
142 auto result = new_city();
143 set_name(result, field_value_of_name);
144 return result;
145 }
146
148 {
150 journal.delete_from(Table_Id(1), record.get_record_id());
151 }
152
154 {
155 for (size_t i = size; i > 0;)
156 delete_city(v[--i]);
157 }
158
159 void set_name(id_of_city record, const std::string& field_value_of_name)
160 {
161 internal_update_city__name(record.get_record_id(), field_value_of_name);
162 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(1), field_value_of_name);
163 }
164
165 template<typename F> void update_vector_of_name(id_of_city record, size_t size, F f)
166 {
167 std::exception_ptr exception;
168 joedb::Span<std::string> span(&storage_of_city.field_value_of_name[record.get_id() - 1], size);
169 try {f(span);}
170 catch (...) {exception = std::current_exception();}
172 journal.update_vector_string(Table_Id(1), record.get_record_id(), Field_Id(1), size, (span.begin()));
173 if (exception)
174 std::rethrow_exception(exception);
175 }
176
177
178 void clear_person_table();
179
181 {
182 id_of_person result(Record_Id(storage_of_person.freedom_keeper.get_free_record() - 1));
183 storage_of_person.resize(storage_of_person.freedom_keeper.size());
185
186 journal.insert_into(Table_Id(2), result.get_record_id());
187 return result;
188 }
189
191 {
192 id_of_person result(Record_Id(storage_of_person.size() + 1));
193 storage_of_person.resize(storage_of_person.size() + size);
195 journal.insert_vector(Table_Id(2), result.get_record_id(), size);
196 return result;
197 }
198
200 (
201 const std::string& field_value_of_first_name,
202 const std::string& field_value_of_last_name,
203 id_of_city field_value_of_home
204 )
205 {
206 auto result = new_person();
207 set_first_name(result, field_value_of_first_name);
208 set_last_name(result, field_value_of_last_name);
209 set_home(result, field_value_of_home);
210 return result;
211 }
212
214 {
216 journal.delete_from(Table_Id(2), record.get_record_id());
217 }
218
220 {
221 for (size_t i = size; i > 0;)
222 delete_person(v[--i]);
223 }
224
225 void set_first_name(id_of_person record, const std::string& field_value_of_first_name)
226 {
227 internal_update_person__first_name(record.get_record_id(), field_value_of_first_name);
228 journal.update_string(Table_Id(2), record.get_record_id(), Field_Id(1), field_value_of_first_name);
229 }
230
231 template<typename F> void update_vector_of_first_name(id_of_person record, size_t size, F f)
232 {
233 std::exception_ptr exception;
234 joedb::Span<std::string> span(&storage_of_person.field_value_of_first_name[record.get_id() - 1], size);
235 try {f(span);}
236 catch (...) {exception = std::current_exception();}
238 journal.update_vector_string(Table_Id(2), record.get_record_id(), Field_Id(1), size, (span.begin()));
239 if (exception)
240 std::rethrow_exception(exception);
241 }
242
243 void set_last_name(id_of_person record, const std::string& field_value_of_last_name)
244 {
245 internal_update_person__last_name(record.get_record_id(), field_value_of_last_name);
246 journal.update_string(Table_Id(2), record.get_record_id(), Field_Id(2), field_value_of_last_name);
247 }
248
249 template<typename F> void update_vector_of_last_name(id_of_person record, size_t size, F f)
250 {
251 std::exception_ptr exception;
252 joedb::Span<std::string> span(&storage_of_person.field_value_of_last_name[record.get_id() - 1], size);
253 try {f(span);}
254 catch (...) {exception = std::current_exception();}
256 journal.update_vector_string(Table_Id(2), record.get_record_id(), Field_Id(2), size, (span.begin()));
257 if (exception)
258 std::rethrow_exception(exception);
259 }
260
261 void set_home(id_of_person record, id_of_city field_value_of_home)
262 {
263 internal_update_person__home(record.get_record_id(), field_value_of_home);
264 journal.update_reference(Table_Id(2), record.get_record_id(), Field_Id(3), field_value_of_home.get_record_id());
265 }
266
267 template<typename F> void update_vector_of_home(id_of_person record, size_t size, F f)
268 {
269 std::exception_ptr exception;
270 joedb::Span<id_of_city> span(&storage_of_person.field_value_of_home[record.get_id() - 1], size);
271 try {f(span);}
272 catch (...) {exception = std::current_exception();}
274 journal.update_vector_reference(Table_Id(2), record.get_record_id(), Field_Id(3), size, reinterpret_cast<Record_Id *>(span.begin()));
275 if (exception)
276 std::rethrow_exception(exception);
277 }
278
279
280 };}
281
282#endif
virtual std::string read_blob_data(Blob blob) const
const Buffered_File & get_file() const
T * begin()
Definition Span.h:40
Blob write_blob_data(const std::string &data) final
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) final
int64_t ahead_of_checkpoint() const noexcept
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 checkpoint(Commit_Level commit_level) final
void default_checkpoint()
Definition Writable.cpp:32
Handle concurrent access to a joedb::Buffered_File using a joedb::Connection.
Definition Client.h:45
Store all the tables of the database.
Definition Database.h:101
void internal_update_vector_person__first_name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:280
void internal_update_vector_city__name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:250
void internal_insert_person(Record_Id record_id)
Definition Database.h:220
void internal_update_vector_person__home(Record_Id record_id, size_t size, const id_of_city *value)
Definition Database.h:338
detail::data_of_city storage_of_city
Definition Database.h:128
detail::data_of_person storage_of_person
Definition Database.h:130
void internal_update_vector_person__last_name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:310
void comment(const std::string &comment) override
Definition Database.h:577
void timestamp(int64_t timestamp) override
Definition Database.h:578
void internal_update_person__home(Record_Id record_id, id_of_city field_value_of_home)
Definition Database.h:328
void internal_update_person__first_name(Record_Id record_id, const std::string &field_value_of_first_name)
Definition Database.h:268
void internal_update_person__last_name(Record_Id record_id, const std::string &field_value_of_last_name)
Definition Database.h:298
void internal_insert_city(Record_Id record_id)
Definition Database.h:204
void internal_update_city__name(Record_Id record_id, const std::string &field_value_of_name)
Definition Database.h:238
void internal_delete_person(Record_Id record_id)
Definition Database.h:194
void internal_delete_city(Record_Id record_id)
Definition Database.h:187
void internal_vector_insert_city(Record_Id record_id, size_t size)
Definition Database.h:210
void internal_vector_insert_person(Record_Id record_id, size_t size)
Definition Database.h:226
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.
void update_vector_of_last_name(id_of_person record, size_t size, F f)
id_of_person new_person(const std::string &field_value_of_first_name, const std::string &field_value_of_last_name, id_of_city field_value_of_home)
void set_name(id_of_city record, const std::string &field_value_of_name)
void delete_vector_of_city(id_of_city v, size_t size)
void set_first_name(id_of_person record, const std::string &field_value_of_first_name)
id_of_city new_vector_of_city(size_t size)
void checkpoint(joedb::Commit_Level commit_level) final
void update_vector_of_home(id_of_person record, size_t size, F f)
void set_last_name(id_of_person record, const std::string &field_value_of_last_name)
void update_vector_of_first_name(id_of_person record, size_t size, F f)
joedb::Blob write_blob_data(const std::string &data) final
std::string read_blob_data(joedb::Blob blob) const
id_of_city new_city(const std::string &field_value_of_name)
void set_home(id_of_person record, id_of_city field_value_of_home)
void write_comment(const std::string &comment)
const joedb::Readonly_Journal & get_journal() const
void delete_vector_of_person(id_of_person v, size_t size)
void update_vector_of_name(id_of_city record, size_t size, F f)
void delete_city(id_of_city record)
id_of_person new_vector_of_person(size_t size)
void delete_person(id_of_person record)
Strongly-typed wrapper around an integer representing a row of the city table.
Definition ids.h:25
constexpr Record_Id get_record_id() const
Definition ids.h:36
constexpr size_t get_id() const
Definition ids.h:35
Strongly-typed wrapper around an integer representing a row of the person table.
Definition ids.h:48
constexpr Record_Id get_record_id() const
Definition ids.h:59
constexpr size_t get_id() const
Definition ids.h:58
Commit_Level
Definition Writable.h:13
Automatically generated by joedbc.
Definition Client.h:19