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 settings_Writable_Database_declared
13#define settings_Writable_Database_declared
14
15#include "Database.h"
16#include "joedb/Span.h"
17
18namespace settings
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
52 void add_field
53 (
54 Table_Id table_id,
55 const std::string &name,
56 joedb::Type type
57 ) override;
58
59 void create_table(const std::string &name) override;
60
62 (
64 bool perform_initialization,
66 joedb::Commit_Level commit_level
67 );
68
69 public:
71 (
75 );
76
77 const joedb::Readonly_Journal &get_journal() const {return journal;}
78
79 std::string read_blob_data(joedb::Blob blob) const
80 {
81 return journal.get_file().read_blob_data(blob);
82 }
83
84 joedb::Blob write_blob_data(const std::string &data) final
85 {
86 return journal.write_blob_data(data);
87 }
88
89 int64_t ahead_of_checkpoint() const
90 {
91 return journal.ahead_of_checkpoint();
92 }
93
98
103
108
110 {
111 journal.default_checkpoint();
112 }
113
114 void checkpoint(joedb::Commit_Level commit_level) final
115 {
116 journal.checkpoint(commit_level);
117 }
118
119 void write_comment(const std::string &comment);
120 void write_timestamp();
121 void write_timestamp(int64_t timestamp);
122 void write_valid_data();
123 void flush() override {journal.flush();}
124
125 private:
126 id_of_settings new_settings()
127 {
128 id_of_settings result(Record_Id(storage_of_settings.freedom_keeper.get_free_record() - 1));
129 storage_of_settings.resize(storage_of_settings.freedom_keeper.size());
130 internal_insert_settings(result.get_record_id());
131
132 journal.insert_into(Table_Id(1), result.get_record_id());
133 return result;
134 }
135
136 id_of_settings new_settings
137 (
138 bool field_value_of_dark_mode,
139 const std::string& field_value_of_host,
140 const std::string& field_value_of_user
141 )
142 {
143 auto result = new_settings();
144 set_dark_mode(result, field_value_of_dark_mode);
145 set_host(result, field_value_of_host);
146 set_user(result, field_value_of_user);
147 return result;
148 }
149
150 public:
151 void set_dark_mode(id_of_settings record, bool field_value_of_dark_mode)
152 {
153 internal_update_settings__dark_mode(record.get_record_id(), field_value_of_dark_mode);
154 journal.update_boolean(Table_Id(1), record.get_record_id(), Field_Id(1), field_value_of_dark_mode);
155 }
156
157 template<typename F> void update_vector_of_dark_mode(id_of_settings record, size_t size, F f)
158 {
159 std::exception_ptr exception;
160 joedb::Span<char> span(&storage_of_settings.field_value_of_dark_mode[record.get_id() - 1], size);
161 try {f(span);}
162 catch (...) {exception = std::current_exception();}
164 journal.update_vector_boolean(Table_Id(1), record.get_record_id(), Field_Id(1), size, (span.begin()));
165 if (exception)
166 std::rethrow_exception(exception);
167 }
168
169 void set_host(id_of_settings record, const std::string& field_value_of_host)
170 {
171 internal_update_settings__host(record.get_record_id(), field_value_of_host);
172 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(2), field_value_of_host);
173 }
174
175 template<typename F> void update_vector_of_host(id_of_settings record, size_t size, F f)
176 {
177 std::exception_ptr exception;
178 joedb::Span<std::string> span(&storage_of_settings.field_value_of_host[record.get_id() - 1], size);
179 try {f(span);}
180 catch (...) {exception = std::current_exception();}
182 journal.update_vector_string(Table_Id(1), record.get_record_id(), Field_Id(2), size, (span.begin()));
183 if (exception)
184 std::rethrow_exception(exception);
185 }
186
187 void set_user(id_of_settings record, const std::string& field_value_of_user)
188 {
189 internal_update_settings__user(record.get_record_id(), field_value_of_user);
190 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(3), field_value_of_user);
191 }
192
193 template<typename F> void update_vector_of_user(id_of_settings record, size_t size, F f)
194 {
195 std::exception_ptr exception;
196 joedb::Span<std::string> span(&storage_of_settings.field_value_of_user[record.get_id() - 1], size);
197 try {f(span);}
198 catch (...) {exception = std::current_exception();}
200 journal.update_vector_string(Table_Id(1), record.get_record_id(), Field_Id(3), size, (span.begin()));
201 if (exception)
202 std::rethrow_exception(exception);
203 }
204
205
206 };}
207
208#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
int64_t ahead_of_checkpoint() const noexcept
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:76
void internal_update_vector_settings__dark_mode(Record_Id record_id, size_t size, const char *value)
Definition Database.h:132
void internal_update_settings__dark_mode(Record_Id record_id, bool field_value_of_dark_mode)
Definition Database.h:122
void internal_insert_settings(Record_Id record_id)
Definition Database.h:111
friend class id_of_settings
Definition Database.h:78
void internal_update_vector_settings__user(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:180
void timestamp(int64_t timestamp) override
Definition Database.h:377
void internal_update_settings__host(Record_Id record_id, const std::string &field_value_of_host)
Definition Database.h:146
void internal_update_vector_settings__host(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:156
detail::data_of_settings storage_of_settings
Definition Database.h:99
void internal_update_settings__user(Record_Id record_id, const std::string &field_value_of_user)
Definition Database.h:170
void comment(const std::string &comment) override
Definition Database.h:376
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 set_dark_mode(id_of_settings record, bool field_value_of_dark_mode)
void write_comment(const std::string &comment)
const joedb::Readonly_Journal & get_journal() const
void update_vector_of_dark_mode(id_of_settings record, size_t size, F f)
void set_user(id_of_settings record, const std::string &field_value_of_user)
std::string read_blob_data(joedb::Blob blob) const
void update_vector_of_host(id_of_settings record, size_t size, F f)
joedb::Blob write_blob_data(const std::string &data) final
void set_host(id_of_settings record, const std::string &field_value_of_host)
void update_vector_of_user(id_of_settings record, size_t size, F f)
void checkpoint(joedb::Commit_Level commit_level) final
Strongly-typed wrapper around an integer representing a row of the settings table.
Definition ids.h:25
constexpr size_t get_id() const
Definition ids.h:35
constexpr Record_Id get_record_id() const
Definition ids.h:36
Commit_Level
Definition Writable.h:13
Automatically generated by joedbc.
Definition Client.h:19