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 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();
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_city_table();
94
96 {
97 id_of_city result(Record_Id(storage_of_city.freedom_keeper.get_free_record() - 1));
98 storage_of_city.resize(storage_of_city.freedom_keeper.size());
100
101 journal.insert_into(Table_Id(1), result.get_record_id());
102 return result;
103 }
104
106 {
107 id_of_city result(Record_Id(storage_of_city.size() + 1));
108 storage_of_city.resize(storage_of_city.size() + size);
110 journal.insert_vector(Table_Id(1), result.get_record_id(), size);
111 return result;
112 }
113
115 (
116 const std::string& field_value_of_name
117 )
118 {
119 auto result = new_city();
120 set_name(result, field_value_of_name);
121 return result;
122 }
123
125 {
127 journal.delete_from(Table_Id(1), record.get_record_id());
128 }
129
131 {
132 for (size_t i = size; i > 0;)
133 internal_delete_city(v[--i].get_record_id());
134 journal.delete_vector(Table_Id(1), v.get_record_id(), size);
135 }
136
137 void set_name(id_of_city record, const std::string& field_value_of_name)
138 {
139 internal_update_city__name(record.get_record_id(), field_value_of_name);
140 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(1), field_value_of_name);
141 }
142
143 template<typename F> void update_vector_of_name(id_of_city record, size_t size, F f)
144 {
145 std::exception_ptr exception;
146 joedb::Span<std::string> span(&storage_of_city.field_value_of_name[record.get_id() - 1], size);
147 try {f(span);}
148 catch (...) {exception = std::current_exception();}
150 journal.update_vector_string(Table_Id(1), record.get_record_id(), Field_Id(1), size, (span.begin()));
151 if (exception)
152 std::rethrow_exception(exception);
153 }
154
155
156 void clear_person_table();
157
159 {
160 id_of_person result(Record_Id(storage_of_person.freedom_keeper.get_free_record() - 1));
161 storage_of_person.resize(storage_of_person.freedom_keeper.size());
163
164 journal.insert_into(Table_Id(2), result.get_record_id());
165 return result;
166 }
167
169 {
170 id_of_person result(Record_Id(storage_of_person.size() + 1));
171 storage_of_person.resize(storage_of_person.size() + size);
173 journal.insert_vector(Table_Id(2), result.get_record_id(), size);
174 return result;
175 }
176
178 (
179 const std::string& field_value_of_first_name,
180 const std::string& field_value_of_last_name,
181 id_of_city field_value_of_home
182 )
183 {
184 auto result = new_person();
185 set_first_name(result, field_value_of_first_name);
186 set_last_name(result, field_value_of_last_name);
187 set_home(result, field_value_of_home);
188 return result;
189 }
190
192 {
194 journal.delete_from(Table_Id(2), record.get_record_id());
195 }
196
198 {
199 for (size_t i = size; i > 0;)
200 internal_delete_person(v[--i].get_record_id());
201 journal.delete_vector(Table_Id(2), v.get_record_id(), size);
202 }
203
204 void set_first_name(id_of_person record, const std::string& field_value_of_first_name)
205 {
206 internal_update_person__first_name(record.get_record_id(), field_value_of_first_name);
207 journal.update_string(Table_Id(2), record.get_record_id(), Field_Id(1), field_value_of_first_name);
208 }
209
210 template<typename F> void update_vector_of_first_name(id_of_person record, size_t size, F f)
211 {
212 std::exception_ptr exception;
213 joedb::Span<std::string> span(&storage_of_person.field_value_of_first_name[record.get_id() - 1], size);
214 try {f(span);}
215 catch (...) {exception = std::current_exception();}
217 journal.update_vector_string(Table_Id(2), record.get_record_id(), Field_Id(1), size, (span.begin()));
218 if (exception)
219 std::rethrow_exception(exception);
220 }
221
222 void set_last_name(id_of_person record, const std::string& field_value_of_last_name)
223 {
224 internal_update_person__last_name(record.get_record_id(), field_value_of_last_name);
225 journal.update_string(Table_Id(2), record.get_record_id(), Field_Id(2), field_value_of_last_name);
226 }
227
228 template<typename F> void update_vector_of_last_name(id_of_person record, size_t size, F f)
229 {
230 std::exception_ptr exception;
231 joedb::Span<std::string> span(&storage_of_person.field_value_of_last_name[record.get_id() - 1], size);
232 try {f(span);}
233 catch (...) {exception = std::current_exception();}
235 journal.update_vector_string(Table_Id(2), record.get_record_id(), Field_Id(2), size, (span.begin()));
236 if (exception)
237 std::rethrow_exception(exception);
238 }
239
240 void set_home(id_of_person record, id_of_city field_value_of_home)
241 {
242 internal_update_person__home(record.get_record_id(), field_value_of_home);
243 journal.update_reference(Table_Id(2), record.get_record_id(), Field_Id(3), field_value_of_home.get_record_id());
244 }
245
246 template<typename F> void update_vector_of_home(id_of_person record, size_t size, F f)
247 {
248 std::exception_ptr exception;
249 joedb::Span<id_of_city> span(&storage_of_person.field_value_of_home[record.get_id() - 1], size);
250 try {f(span);}
251 catch (...) {exception = std::current_exception();}
253 journal.update_vector_reference(Table_Id(2), record.get_record_id(), Field_Id(3), size, reinterpret_cast<Record_Id *>(span.begin()));
254 if (exception)
255 std::rethrow_exception(exception);
256 }
257
258
259 };}
260
261#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: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)
std::string read_blob(joedb::Blob blob) const
void delete_vector_of_city(id_of_city v, size_t size)
joedb::Blob write_blob(const std::string &data) final
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 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)
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 auto get_id() const
Definition ids.h:35
constexpr Record_Id get_record_id() const
Definition ids.h:36
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 auto get_id() const
Definition ids.h:58
Automatically generated by joedbc.
Definition Client.h:19