Joedb 10.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: 10.5.0
8// joedbc compilation time: Oct 25 2026 16:06:59
9// Generation of this file: 2026-10-25 19:48:05 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#ifndef tutorial_rpc_population_Writable_Database_declared
13#define tutorial_rpc_population_Writable_Database_declared
14
15#include "joedb/Span.h"
16
17#include "Database_Writable.h"
18
19#include <utility>
20
22{
23 namespace detail
24 {
25 class Client_Data;
26 }
27
28 class Client;
29 class Multiplexer;
30 class Memory_Database;
31
32 /// A @ref Database that contains a @ref joedb::Writable_Journal and keeps them in sync
33 class Writable_Database: public Database_Writable
34 {
35 friend class detail::Client_Data;
36 friend class Client;
37 friend class Multiplexer;
38 friend class Memory_Database;
39
40 private:
42 bool ready_to_write;
43
44 void play_journal();
45 void auto_upgrade();
46 void check_single_row();
47 void initialize();
48
49 Writable_Database
50 (
52 joedb::Recovery recovery,
53 bool perform_initialization
54 );
55
56 public:
57 Writable_Database(joedb::Abstract_File &file);
58
59 Writable_Database
60 (
62 joedb::Recovery recovery
63 );
64
65 const joedb::Readonly_Journal &get_journal() const {return journal;}
66
67 std::string read_blob(joedb::Blob blob) const
68 {
69 return journal.get_file().read_blob(blob);
70 }
71
72 joedb::Blob write_blob(std::string_view data) override
73 {
74 return journal.write_blob(data);
75 }
76
77 int64_t ahead_of_checkpoint() const
78 {
79 return journal.ahead_of_checkpoint();
80 }
81
82 void soft_checkpoint() override
83 {
84 journal.soft_checkpoint();
85 }
86
87 void hard_checkpoint() override
88 {
89 journal.hard_checkpoint();
90 }
91
92 void write_comment(const std::string &comment);
93 void write_timestamp();
94 void write_timestamp(int64_t timestamp);
95 void write_valid_data();
96 void flush() override {journal.flush();}
97
98 void clear_city_table();
99
101 {
102 id_of_city result(Record_Id(storage_of_city.freedom_keeper.get_free_record()));
103 storage_of_city.resize(storage_of_city.freedom_keeper.size());
105
106 journal.insert_into(Table_Id(1), result.get_record_id());
107 return result;
108 }
109
111 {
112 if (id.get_record_id() >= Record_Id(storage_of_city.size()))
113 storage_of_city.resize(id.get_id() + 1);
114 internal_insert_city(id.get_record_id());
115 journal.insert_into(Table_Id(1), id.get_record_id());
116 }
117
119 {
120 id_of_city result(Record_Id(storage_of_city.size()));
121 storage_of_city.resize(storage_of_city.size() + size);
123 journal.insert_vector(Table_Id(1), result.get_record_id(), size);
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
141 void clear_data_table();
142
144 {
145 id_of_data result(Record_Id(storage_of_data.freedom_keeper.get_free_record()));
146 storage_of_data.resize(storage_of_data.freedom_keeper.size());
148
149 journal.insert_into(Table_Id(2), result.get_record_id());
150 return result;
151 }
152
154 {
155 if (id.get_record_id() >= Record_Id(storage_of_data.size()))
156 storage_of_data.resize(id.get_id() + 1);
157 internal_insert_data(id.get_record_id());
158 journal.insert_into(Table_Id(2), id.get_record_id());
159 }
160
162 {
163 id_of_data result(Record_Id(storage_of_data.size()));
164 storage_of_data.resize(storage_of_data.size() + size);
166 journal.insert_vector(Table_Id(2), result.get_record_id(), size);
167 return result;
168 }
169
171 (
172 std::string field_value_of_city_name,
173 id_of_city field_value_of_city,
174 int64_t field_value_of_population
175 )
176 {
177 auto result = new_data();
178 set_city_name(result, std::move(field_value_of_city_name));
179 set_city(result, field_value_of_city);
180 set_population(result, field_value_of_population);
181 return result;
182 }
183
185 {
187 journal.delete_from(Table_Id(2), record.get_record_id());
188 }
189
191 {
192 for (size_t i = size; i > 0;)
193 internal_delete_data(v[--i].get_record_id());
194 journal.delete_vector(Table_Id(2), v.get_record_id(), size);
195 }
196
197 void set_city_name(id_of_data record, std::string field_value_of_city_name)
198 {
199 internal_update_data__city_name(record.get_record_id(), std::move(field_value_of_city_name));
200 journal.update_string(Table_Id(2), record.get_record_id(), Field_Id(1), get_city_name(record));
201 }
202
203 template<typename F> void update_vector_of_city_name(id_of_data record, size_t size, F f)
204 {
205 JOEDB_DEBUG_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record.get_record_id(), size));
206 joedb::Span<std::string> span(&storage_of_data.field_value_of_city_name.data()[record.get_id()], size);
207 f(span);
209 journal.update_vector_string(Table_Id(2), record.get_record_id(), Field_Id(1), size, (span.begin()));
210 }
211
212 void set_city(id_of_data record, id_of_city field_value_of_city)
213 {
214 internal_update_data__city(record.get_record_id(), field_value_of_city);
215 journal.update_reference(Table_Id(2), record.get_record_id(), Field_Id(2), field_value_of_city.get_record_id());
216 }
217
218 template<typename F> void update_vector_of_city(id_of_data record, size_t size, F f)
219 {
220 JOEDB_DEBUG_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record.get_record_id(), size));
221 joedb::Span<id_of_city> span(&storage_of_data.field_value_of_city.data()[record.get_id()], size);
222 f(span);
224 journal.update_vector_reference(Table_Id(2), record.get_record_id(), Field_Id(2), size, reinterpret_cast<Record_Id *>(span.begin()));
225 }
226
227 void set_population(id_of_data record, int64_t field_value_of_population)
228 {
229 internal_update_data__population(record.get_record_id(), field_value_of_population);
230 journal.update_int64(Table_Id(2), record.get_record_id(), Field_Id(3), field_value_of_population);
231 }
232
233 template<typename F> void update_vector_of_population(id_of_data record, size_t size, F f)
234 {
235 JOEDB_DEBUG_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record.get_record_id(), size));
236 joedb::Span<int64_t> span(&storage_of_data.field_value_of_population.data()[record.get_id()], size);
237 f(span);
239 journal.update_vector_int64(Table_Id(2), record.get_record_id(), Field_Id(3), size, (span.begin()));
240 }
241
242
243 };}
244
245#endif
T * begin()
Definition Span.h:39
constexpr Record_Id get_record_id() const
Definition ids.h:36
Handle concurrent access to a joedb::Abstract_File using a joedb::Connection.
Definition Client.h:44
void timestamp(int64_t timestamp) override
void comment(const std::string &comment) override
detail::data_of_data storage_of_data
Definition Database.h:104
detail::data_of_city storage_of_city
Definition Database.h:102
void internal_update_vector_data__city_name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:153
void internal_update_vector_data__city(Record_Id record_id, size_t size, const id_of_city *value)
Definition Database.h:176
void internal_vector_insert_city(Record_Id record_id, size_t size)
Definition Database.h:126
void internal_update_data__population(Record_Id record_id, int64_t field_value_of_population)
Definition Database.h:189
void internal_delete_city(Record_Id record_id)
Definition Database.h:107
void internal_update_data__city(Record_Id record_id, id_of_city field_value_of_city)
Definition Database.h:166
void internal_delete_data(Record_Id record_id)
Definition Database.h:112
const std::string & get_city_name(id_of_data record) const
Definition Database.h:264
void internal_insert_data(Record_Id record_id)
Definition Database.h:131
void internal_update_data__city_name(Record_Id record_id, std::string field_value_of_city_name)
Definition Database.h:143
void internal_update_vector_data__population(Record_Id record_id, size_t size, const int64_t *value)
Definition Database.h:199
void internal_vector_insert_data(Record_Id record_id, size_t size)
Definition Database.h:136
void internal_insert_city(Record_Id record_id)
Definition Database.h:121
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
void set_city(id_of_data record, id_of_city field_value_of_city)
void write_comment(const std::string &comment)
joedb::Blob write_blob(std::string_view data) override
void delete_vector_of_city(id_of_city v, size_t size)
void update_vector_of_city_name(id_of_data record, size_t size, F f)
void set_city_name(id_of_data record, std::string field_value_of_city_name)
void delete_vector_of_data(id_of_data v, size_t size)
void update_vector_of_city(id_of_data record, size_t size, F f)
const joedb::Readonly_Journal & get_journal() const
std::string read_blob(joedb::Blob blob) const
void update_vector_of_population(id_of_data record, size_t size, F f)
void set_population(id_of_data record, int64_t field_value_of_population)
id_of_data new_data(std::string field_value_of_city_name, id_of_city field_value_of_city, int64_t field_value_of_population)
Strongly-typed wrapper around an integer representing a row of the data table.
Definition ids.h:27
constexpr auto get_id() const
Definition ids.h:37
constexpr Record_Id get_record_id() const
Definition ids.h:38
#define JOEDB_DEBUG_ASSERT(x)
assertion tested in debug mode
Definition assert.h:19
Automatically generated by joedbc.
Definition Client.h:19
tutorial::id_of_city id_of_city
Definition ids.h:23