Joedb 10.2.1
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: 10.2.1
8// joedbc compilation time: Sep 15 2025 20:22:33
9// Generation of this file: 2025-09-15 18:23:01 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#ifndef tutorial_Writable_Database_declared
13#define tutorial_Writable_Database_declared
14
15#include "joedb/Span.h"
16
17#include "Database_Writable.h"
18
19namespace tutorial
20{
21 namespace detail
22 {
23 class Client_Data;
24 }
25
26 class Client;
27 class Multiplexer;
28 class Memory_Database;
29
30 /// A @ref Database that contains a @ref joedb::Writable_Journal and keeps them in sync
32 {
33 friend class detail::Client_Data;
34 friend class Client;
35 friend class Multiplexer;
36 friend class Memory_Database;
37
38 private:
40 bool ready_to_write;
41
42 void play_journal();
43 void auto_upgrade();
44 void check_single_row();
45 void initialize();
46
48 (
50 joedb::Recovery recovery,
51 bool perform_initialization
52 );
53
54 public:
56
58 (
60 joedb::Recovery recovery
61 );
62
63 const joedb::Readonly_Journal &get_journal() const {return journal;}
64
65 std::string read_blob(joedb::Blob blob) const
66 {
67 return journal.get_file().read_blob(blob);
68 }
69
70 joedb::Blob write_blob(const std::string &data) override
71 {
72 return journal.write_blob(data);
73 }
74
75 int64_t ahead_of_checkpoint() const
76 {
77 return journal.ahead_of_checkpoint();
78 }
79
80 void soft_checkpoint() override
81 {
82 journal.soft_checkpoint();
83 }
84
85 void hard_checkpoint() override
86 {
87 journal.hard_checkpoint();
88 }
89
90 void write_comment(const std::string &comment);
91 void write_timestamp();
92 void write_timestamp(int64_t timestamp);
93 void write_valid_data();
94 void flush() override {journal.flush();}
95
96 void clear_city_table();
97
99 {
100 id_of_city result(Record_Id(storage_of_city.freedom_keeper.get_free_record()));
101 storage_of_city.resize(storage_of_city.freedom_keeper.size());
103
104 journal.insert_into(Table_Id(1), result.get_record_id());
105 return result;
106 }
107
109 {
110 id_of_city result(Record_Id(storage_of_city.size()));
111 storage_of_city.resize(storage_of_city.size() + size);
113 journal.insert_vector(Table_Id(1), result.get_record_id(), size);
114 return result;
115 }
116
118 (
119 const std::string& field_value_of_name
120 )
121 {
122 auto result = new_city();
123 set_name(result, field_value_of_name);
124 return result;
125 }
126
128 {
130 journal.delete_from(Table_Id(1), record.get_record_id());
131 }
132
134 {
135 for (size_t i = size; i > 0;)
136 internal_delete_city(v[--i].get_record_id());
137 journal.delete_vector(Table_Id(1), v.get_record_id(), size);
138 }
139
140 void set_name(id_of_city record, const std::string& field_value_of_name)
141 {
142 internal_update_city__name(record.get_record_id(), field_value_of_name);
143 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(1), field_value_of_name);
144 }
145
146 template<typename F> void update_vector_of_name(id_of_city record, size_t size, F f)
147 {
148 joedb::Span<std::string> span(&storage_of_city.field_value_of_name.data()[record.get_id()], size);
149 f(span);
151 journal.update_vector_string(Table_Id(1), record.get_record_id(), Field_Id(1), size, (span.begin()));
152 }
153
154
155 void clear_person_table();
156
158 {
159 id_of_person result(Record_Id(storage_of_person.freedom_keeper.get_free_record()));
160 storage_of_person.resize(storage_of_person.freedom_keeper.size());
162
163 journal.insert_into(Table_Id(2), result.get_record_id());
164 return result;
165 }
166
168 {
170 storage_of_person.resize(storage_of_person.size() + size);
172 journal.insert_vector(Table_Id(2), result.get_record_id(), size);
173 return result;
174 }
175
177 (
178 const std::string& field_value_of_first_name,
179 const std::string& field_value_of_last_name,
180 id_of_city field_value_of_home
181 )
182 {
183 auto result = new_person();
184 set_first_name(result, field_value_of_first_name);
185 set_last_name(result, field_value_of_last_name);
186 set_home(result, field_value_of_home);
187 return result;
188 }
189
191 {
193 journal.delete_from(Table_Id(2), record.get_record_id());
194 }
195
197 {
198 for (size_t i = size; i > 0;)
199 internal_delete_person(v[--i].get_record_id());
200 journal.delete_vector(Table_Id(2), v.get_record_id(), size);
201 }
202
203 void set_first_name(id_of_person record, const std::string& field_value_of_first_name)
204 {
205 internal_update_person__first_name(record.get_record_id(), field_value_of_first_name);
206 journal.update_string(Table_Id(2), record.get_record_id(), Field_Id(1), field_value_of_first_name);
207 }
208
209 template<typename F> void update_vector_of_first_name(id_of_person record, size_t size, F f)
210 {
211 joedb::Span<std::string> span(&storage_of_person.field_value_of_first_name.data()[record.get_id()], size);
212 f(span);
214 journal.update_vector_string(Table_Id(2), record.get_record_id(), Field_Id(1), size, (span.begin()));
215 }
216
217 void set_last_name(id_of_person record, const std::string& field_value_of_last_name)
218 {
219 internal_update_person__last_name(record.get_record_id(), field_value_of_last_name);
220 journal.update_string(Table_Id(2), record.get_record_id(), Field_Id(2), field_value_of_last_name);
221 }
222
223 template<typename F> void update_vector_of_last_name(id_of_person record, size_t size, F f)
224 {
225 joedb::Span<std::string> span(&storage_of_person.field_value_of_last_name.data()[record.get_id()], size);
226 f(span);
228 journal.update_vector_string(Table_Id(2), record.get_record_id(), Field_Id(2), size, (span.begin()));
229 }
230
231 void set_home(id_of_person record, id_of_city field_value_of_home)
232 {
233 internal_update_person__home(record.get_record_id(), field_value_of_home);
234 journal.update_reference(Table_Id(2), record.get_record_id(), Field_Id(3), field_value_of_home.get_record_id());
235 }
236
237 template<typename F> void update_vector_of_home(id_of_person record, size_t size, F f)
238 {
239 joedb::Span<id_of_city> span(&storage_of_person.field_value_of_home.data()[record.get_id()], size);
240 f(span);
242 journal.update_vector_reference(Table_Id(2), record.get_record_id(), Field_Id(3), size, reinterpret_cast<Record_Id *>(span.begin()));
243 }
244
245
246 };}
247
248#endif
std::string read_blob(Blob blob) const
const Abstract_File & get_file() const
T * begin()
Definition Span.h:39
void delete_vector(Table_Id table_id, Record_Id record_id, size_t size) override
void delete_from(Table_Id table_id, Record_Id record_id) override
int64_t ahead_of_checkpoint() const noexcept
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) override
void insert_into(Table_Id table_id, Record_Id record_id) override
Blob write_blob(const std::string &data) override
Handle concurrent access to a joedb::Abstract_File using a joedb::Connection.
Definition Client.h:44
implement joedb::Writable in a Database
void timestamp(int64_t timestamp) override
void comment(const std::string &comment) override
void internal_update_vector_person__first_name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:261
void internal_update_vector_city__name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:232
void internal_insert_person(Record_Id record_id)
Definition Database.h:201
void internal_update_vector_person__home(Record_Id record_id, size_t size, const id_of_city *value)
Definition Database.h:317
detail::data_of_city storage_of_city
Definition Database.h:108
detail::data_of_person storage_of_person
Definition Database.h:110
void internal_update_vector_person__last_name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:290
void internal_update_person__home(Record_Id record_id, id_of_city field_value_of_home)
Definition Database.h:307
void internal_update_person__first_name(Record_Id record_id, const std::string &field_value_of_first_name)
Definition Database.h:249
void internal_update_person__last_name(Record_Id record_id, const std::string &field_value_of_last_name)
Definition Database.h:278
void internal_insert_city(Record_Id record_id)
Definition Database.h:184
void internal_update_city__name(Record_Id record_id, const std::string &field_value_of_name)
Definition Database.h:220
void internal_delete_person(Record_Id record_id)
Definition Database.h:174
void internal_delete_city(Record_Id record_id)
Definition Database.h:167
void internal_vector_insert_city(Record_Id record_id, size_t size)
Definition Database.h:190
void internal_vector_insert_person(Record_Id record_id, size_t size)
Definition Database.h:207
Shortcut to directly build a Writable_Database with a Memory_File.
Write simultaneously to the database and the file (ignore schema changes)
Definition Multiplexer.h:40
A Database that contains a joedb::Writable_Journal and keeps them in sync.
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)
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)
joedb::Blob write_blob(const std::string &data) override
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