Joedb 10.2.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Database_Writable.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_rpc_city_Database_Writable_declared
13#define tutorial_rpc_city_Database_Writable_declared
14
18#include "Database.h"
19
20#include <string>
21#include <stdint.h>
22#include <cstring>
23#include <vector>
24
25namespace tutorial::rpc::city
26{
27 namespace detail
28 {
29 extern const char * schema_string;
30 inline constexpr size_t schema_string_size = 55;
31 }
32
33 class container_of_city;
34
35 /// implement @ref joedb::Writable in a @ref Database
37 {
38 protected:
40 Table_Id current_table_id = Table_Id{0};
41
42 void delete_from(Table_Id table_id, Record_Id record_id) override
43 {
44 if (table_id == Table_Id(1))
45 internal_delete_city(record_id);
46 }
47
48 void insert_into(Table_Id table_id, Record_Id record_id) override
49 {
50 if (to_underlying(record_id) < 0 || (max_record_id && to_underlying(record_id) >= max_record_id))
51 throw_exception("insert_into: too big");
52 if (table_id == Table_Id(1))
53 {
54 if (is_valid_record_id_for_city(record_id))
55 throw_exception("Duplicate insert into table city");
56 if (storage_of_city.size() <= size_t(record_id))
57 storage_of_city.resize(to_underlying(record_id) + 1);
58 internal_insert_city(record_id);
59 }
60 }
61
63 (
64 Table_Id table_id,
65 Record_Id record_id,
66 size_t size
67 ) override
68 {
69 joedb::Freedom_Keeper *fk = nullptr;
70
71 if (table_id == Table_Id(1))
72 fk = &storage_of_city.freedom_keeper;
73
74 if (fk)
75 {
76 JOEDB_RELEASE_ASSERT(fk->is_used_vector(record_id, size));
77 joedb::Writable::delete_vector(table_id, record_id, size);
78 }
79 }
80
82 (
83 Table_Id table_id,
84 Record_Id record_id,
85 size_t size
86 ) override
87 {
88 if
89 (
90 to_underlying(record_id) < 0 ||
91 (max_record_id && (to_underlying(record_id) >= max_record_id || joedb::index_t(size) >= max_record_id))
92 )
93 {
94 throw_exception("insert_vector: null record_id, or too big");
95 }
96 if (table_id == Table_Id(1))
97 {
98 if (storage_of_city.size() < size_t(record_id) + size)
99 storage_of_city.resize(to_underlying(record_id) + size);
100 internal_vector_insert_city(record_id, size);
101 }
102 }
103
105 (
106 Table_Id table_id,
107 Record_Id record_id,
108 Field_Id field_id,
109 const std::string& value
110 )
111 override
112 {
113 if (table_id == Table_Id(1))
114 {
115 if (field_id == Field_Id(1))
116 {
117 internal_update_city__name(record_id, value);
118 return;
119 }
120 return;
121 }
122 }
123
125 (
126 Table_Id table_id,
127 Record_Id record_id,
128 Field_Id field_id,
129 size_t size,
130 const std::string *value
131 )
132 override
133 {
134 if (table_id == Table_Id(1))
135 {
136 if (field_id == Field_Id(1))
137 {
138 internal_update_vector_city__name(record_id, size, value);
139 return;
140 }
141 return;
142 }
143 }
144
146 (
147 Table_Id table_id,
148 Record_Id record_id,
149 Field_Id field_id,
150 size_t &capacity
151 )
152 override
153 {
154 if (table_id == Table_Id(1))
155 {
156 capacity = size_t(storage_of_city.freedom_keeper.size());
157 if (field_id == Field_Id(1))
158 {
159 return (storage_of_city.field_value_of_name.data() + to_underlying(record_id));
160 }
161 return nullptr;
162 }
163 return nullptr;
164 }
165
166 void comment(const std::string &comment) override {}
167 void timestamp(int64_t timestamp) override {}
168 void valid_data() override {}
169
170 bool upgrading_schema = false;
173
175 {
176 return schema_file.get_data().size() < detail::schema_string_size;
177 }
178
180 {
181 constexpr size_t pos = joedb::Header::size;
182 const size_t schema_file_size = schema_file.get_data().size();
183
184 if
185 (
186 schema_file_size < pos ||
187 schema_file_size > detail::schema_string_size ||
188 std::memcmp
189 (
190 detail::schema_string + pos,
191 schema_file.get_data().data() + pos,
192 schema_file_size - pos
193 ) != 0
194 )
195 {
196 throw_exception("Trying to open a file with incompatible schema");
197 }
198 }
199
200 void create_table(const std::string &name) override
201 {
205 }
206
207 void drop_table(Table_Id table_id) override
208 {
209 schema_journal.drop_table(table_id);
211 }
212
214 (
215 Table_Id table_id,
216 const std::string &name
217 ) override
218 {
219 schema_journal.rename_table(table_id, name);
221 }
222
224 (
225 Table_Id table_id,
226 const std::string &name,
227 joedb::Type type
228 ) override
229 {
230 schema_journal.add_field(table_id, name, type);
232 }
233
234 void drop_field(Table_Id table_id, Field_Id field_id) override
235 {
236 schema_journal.drop_field(table_id, field_id);
238 }
239
241 (
242 Table_Id table_id,
243 Field_Id field_id,
244 const std::string &name
245 ) override
246 {
247 schema_journal.rename_field(table_id, field_id, name);
249 }
250
251 void custom(const std::string &name) override
252 {
255 }
256
257 public:
262
264 {
265 max_record_id = record_id;
266 }
267
268 int64_t get_schema_checkpoint() const
269 {
271 }
272
274 {
275 max_record_id = size_t(journal.get_checkpoint());
276 journal.replay_log(*this);
277 max_record_id = 0;
278
279 check_schema();
280
282 throw_exception<joedb::Out_Of_Date>("Schema is out of date. Can't upgrade a read-only database.");
283 }
284 };
285}
286
287#endif
bool is_used_vector(Record_Id index, size_t size) const
std::string & get_data()
Definition Memory_File.h:23
void replay_log(Writable &writable)
int64_t get_checkpoint() const
void add_field(Table_Id table_id, const std::string &name, Type type) override
void custom(const std::string &name) override
void create_table(const std::string &name) override
void rename_table(Table_Id table_id, const std::string &name) override
void drop_table(Table_Id table_id) override
void rename_field(Table_Id table_id, Field_Id field_id, const std::string &name) override
void drop_field(Table_Id table_id, Field_Id field_id) override
Superclass with all joedb journal event listeners as virtual functions.
Definition Writable.h:17
virtual void delete_vector(Table_Id table_id, Record_Id record_id, size_t size)=0
Definition Writable.cpp:44
implement joedb::Writable in a Database
void timestamp(int64_t timestamp) override
void initialize_with_readonly_journal(joedb::Readonly_Journal &journal)
void delete_vector(Table_Id table_id, Record_Id record_id, size_t size) override
void create_table(const std::string &name) override
void delete_from(Table_Id table_id, Record_Id record_id) override
void add_field(Table_Id table_id, const std::string &name, joedb::Type type) override
std::string * get_own_string_storage(Table_Id table_id, Record_Id record_id, Field_Id field_id, size_t &capacity) override
void comment(const std::string &comment) override
void drop_table(Table_Id table_id) override
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) override
void drop_field(Table_Id table_id, Field_Id field_id) override
void update_string(Table_Id table_id, Record_Id record_id, Field_Id field_id, const std::string &value) override
void rename_field(Table_Id table_id, Field_Id field_id, const std::string &name) override
void set_max_record_id(joedb::index_t record_id)
void rename_table(Table_Id table_id, const std::string &name) override
void update_vector_string(Table_Id table_id, Record_Id record_id, Field_Id field_id, size_t size, const std::string *value) override
void custom(const std::string &name) override
void insert_into(Table_Id table_id, Record_Id record_id) override
Store all the tables of the database.
Definition Database.h:63
void internal_insert_city(Record_Id record_id)
Definition Database.h:87
void internal_update_city__name(Record_Id record_id, const std::string &field_value_of_name)
Definition Database.h:99
bool is_valid_record_id_for_city(Record_Id record_id) const
Definition Database.h:78
static void throw_exception(const std::string &message)
Definition Database.h:69
detail::data_of_city storage_of_city
Definition Database.h:77
void internal_vector_insert_city(Record_Id record_id, size_t size)
Definition Database.h:92
void internal_delete_city(Record_Id record_id)
Definition Database.h:80
void internal_update_vector_city__name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:109
#define JOEDB_RELEASE_ASSERT(x)
always-tested assertion (release and debug mode)
Definition assert.h:24
ptrdiff_t index_t
Definition index_types.h:18
Automatically generated by joedbc.
Definition Client.h:19
static constexpr size_t size
Definition Header.h:19