Joedb 10.0.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.0.1
8// joedbc compilation time: Jun 13 2025 15:26:57
9// Generation of this file: 2025-06-13 13:27:16 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#ifndef settings_Writable_Database_declared
13#define settings_Writable_Database_declared
14
15#include "Database_Writable.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 @ref Database that contains a @ref joedb::Writable_Journal and keeps them in sync
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 void initialize();
43
44 void add_field
45 (
46 Table_Id table_id,
47 const std::string &name,
48 joedb::Type type
49 ) override;
50
51 void create_table(const std::string &name) override;
52
54 (
56 joedb::Recovery recovery,
57 bool perform_initialization
58 );
59
60 public:
62
64 (
66 joedb::Recovery recovery
67 );
68
69 const joedb::Readonly_Journal &get_journal() const {return journal;}
70
71 std::string read_blob(joedb::Blob blob) const
72 {
73 return journal.get_file().read_blob(blob);
74 }
75
76 joedb::Blob write_blob(const std::string &data) override
77 {
78 return journal.write_blob(data);
79 }
80
81 int64_t ahead_of_checkpoint() const
82 {
83 return journal.ahead_of_checkpoint();
84 }
85
86 void soft_checkpoint() override
87 {
88 journal.soft_checkpoint();
89 }
90
91 void hard_checkpoint() override
92 {
93 journal.hard_checkpoint();
94 }
95
96 void write_comment(const std::string &comment);
97 void write_timestamp();
98 void write_timestamp(int64_t timestamp);
99 void write_valid_data();
100 void flush() override {journal.flush();}
101
102 private:
103 id_of_settings new_settings()
104 {
105 id_of_settings result(Record_Id(storage_of_settings.freedom_keeper.get_free_record()));
106 storage_of_settings.resize(storage_of_settings.freedom_keeper.size());
107 internal_insert_settings(result.get_record_id());
108
109 journal.insert_into(Table_Id(1), result.get_record_id());
110 return result;
111 }
112
113 id_of_settings new_settings
114 (
115 bool field_value_of_dark_mode,
116 const std::string& field_value_of_host,
117 const std::string& field_value_of_user
118 )
119 {
120 auto result = new_settings();
121 set_dark_mode(result, field_value_of_dark_mode);
122 set_host(result, field_value_of_host);
123 set_user(result, field_value_of_user);
124 return result;
125 }
126
127 public:
128 void set_dark_mode(id_of_settings record, bool field_value_of_dark_mode)
129 {
130 internal_update_settings__dark_mode(record.get_record_id(), field_value_of_dark_mode);
131 journal.update_boolean(Table_Id(1), record.get_record_id(), Field_Id(1), field_value_of_dark_mode);
132 }
133
134 template<typename F> void update_vector_of_dark_mode(id_of_settings record, size_t size, F f)
135 {
136 std::exception_ptr exception;
137 joedb::Span<char> span(&storage_of_settings.field_value_of_dark_mode.data()[record.get_id()], size);
138 try {f(span);}
139 catch (...) {exception = std::current_exception();}
141 journal.update_vector_boolean(Table_Id(1), record.get_record_id(), Field_Id(1), size, (span.begin()));
142 if (exception)
143 std::rethrow_exception(exception);
144 }
145
146 void set_host(id_of_settings record, const std::string& field_value_of_host)
147 {
148 internal_update_settings__host(record.get_record_id(), field_value_of_host);
149 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(2), field_value_of_host);
150 }
151
152 template<typename F> void update_vector_of_host(id_of_settings record, size_t size, F f)
153 {
154 std::exception_ptr exception;
155 joedb::Span<std::string> span(&storage_of_settings.field_value_of_host.data()[record.get_id()], size);
156 try {f(span);}
157 catch (...) {exception = std::current_exception();}
159 journal.update_vector_string(Table_Id(1), record.get_record_id(), Field_Id(2), size, (span.begin()));
160 if (exception)
161 std::rethrow_exception(exception);
162 }
163
164 void set_user(id_of_settings record, const std::string& field_value_of_user)
165 {
166 internal_update_settings__user(record.get_record_id(), field_value_of_user);
167 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(3), field_value_of_user);
168 }
169
170 template<typename F> void update_vector_of_user(id_of_settings record, size_t size, F f)
171 {
172 std::exception_ptr exception;
173 joedb::Span<std::string> span(&storage_of_settings.field_value_of_user.data()[record.get_id()], size);
174 try {f(span);}
175 catch (...) {exception = std::current_exception();}
177 journal.update_vector_string(Table_Id(1), record.get_record_id(), Field_Id(3), size, (span.begin()));
178 if (exception)
179 std::rethrow_exception(exception);
180 }
181
182
183 };}
184
185#endif
const Buffered_File & get_file() const
T * begin()
Definition Span.h:39
Blob write_blob(const std::string &data) override
int64_t ahead_of_checkpoint() const noexcept
void insert_into(Table_Id table_id, Record_Id record_id) override
Handle concurrent access to a joedb::Buffered_File using a joedb::Connection.
Definition Client.h:44
implement joedb::Writable in a Database
void comment(const std::string &comment) override
void timestamp(int64_t timestamp) override
void internal_update_vector_settings__dark_mode(Record_Id record_id, size_t size, const char *value)
Definition Database.h:117
void internal_update_settings__dark_mode(Record_Id record_id, bool field_value_of_dark_mode)
Definition Database.h:107
void internal_insert_settings(Record_Id record_id)
Definition Database.h:95
void internal_update_vector_settings__user(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:163
void internal_update_settings__host(Record_Id record_id, const std::string &field_value_of_host)
Definition Database.h:130
void internal_update_vector_settings__host(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:140
detail::data_of_settings storage_of_settings
Definition Database.h:83
void internal_update_settings__user(Record_Id record_id, const std::string &field_value_of_user)
Definition Database.h:153
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 set_dark_mode(id_of_settings record, bool field_value_of_dark_mode)
void write_comment(const std::string &comment)
std::string read_blob(joedb::Blob blob) const
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)
void update_vector_of_host(id_of_settings record, size_t size, F f)
joedb::Blob write_blob(const std::string &data) override
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)
Strongly-typed wrapper around an integer representing a row of the settings table.
Definition ids.h:25
constexpr Record_Id get_record_id() const
Definition ids.h:36
constexpr auto get_id() const
Definition ids.h:35
Automatically generated by joedbc.
Definition Client.h:19