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 settings_Writable_Database_declared
13#define settings_Writable_Database_declared
14
15#include "Database_Writable.h"
16
17#include <utility>
18
19namespace settings
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
31 class Writable_Database: public Database_Writable
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
47 void add_field
48 (
49 Table_Id table_id,
50 const std::string &name,
51 joedb::Type type
52 ) override;
53
54 void create_table(const std::string &name) override;
55
56 Writable_Database
57 (
59 joedb::Recovery recovery,
60 bool perform_initialization
61 );
62
63 public:
64 Writable_Database(joedb::Abstract_File &file);
65
66 Writable_Database
67 (
69 joedb::Recovery recovery
70 );
71
72 const joedb::Readonly_Journal &get_journal() const {return journal;}
73
74 std::string read_blob(joedb::Blob blob) const
75 {
76 return journal.get_file().read_blob(blob);
77 }
78
79 joedb::Blob write_blob(std::string_view data) override
80 {
81 return journal.write_blob(data);
82 }
83
84 int64_t ahead_of_checkpoint() const
85 {
86 return journal.ahead_of_checkpoint();
87 }
88
89 void soft_checkpoint() override
90 {
91 journal.soft_checkpoint();
92 }
93
94 void hard_checkpoint() override
95 {
96 journal.hard_checkpoint();
97 }
98
99 void write_comment(const std::string &comment);
100 void write_timestamp();
101 void write_timestamp(int64_t timestamp);
102 void write_valid_data();
103 void flush() override {journal.flush();}
104
105 private:
106 id_of_settings new_settings()
107 {
108 id_of_settings result(Record_Id(storage_of_settings.freedom_keeper.get_free_record()));
109 storage_of_settings.resize(storage_of_settings.freedom_keeper.size());
110 internal_insert_settings(result.get_record_id());
111
112 journal.insert_into(Table_Id(1), result.get_record_id());
113 return result;
114 }
115
116 void insert_settings(id_of_settings id)
117 {
118 if (id.get_record_id() >= Record_Id(storage_of_settings.size()))
119 storage_of_settings.resize(id.get_id() + 1);
120 internal_insert_settings(id.get_record_id());
121 journal.insert_into(Table_Id(1), id.get_record_id());
122 }
123
124 id_of_settings new_settings
125 (
126 bool field_value_of_dark_mode,
127 std::string field_value_of_host,
128 std::string field_value_of_user
129 )
130 {
131 auto result = new_settings();
132 set_dark_mode(result, field_value_of_dark_mode);
133 set_host(result, std::move(field_value_of_host));
134 set_user(result, std::move(field_value_of_user));
135 return result;
136 }
137
138 public:
139 void set_dark_mode(id_of_settings record, bool field_value_of_dark_mode)
140 {
141 internal_update_settings__dark_mode(record.get_record_id(), field_value_of_dark_mode);
142 journal.update_boolean(Table_Id(1), record.get_record_id(), Field_Id(1), field_value_of_dark_mode);
143 }
144
145 void set_dark_mode(bool field_value_of_dark_mode)
146 {
147 set_dark_mode(the_settings(), field_value_of_dark_mode);
148 }
149
150 void set_host(id_of_settings record, std::string field_value_of_host)
151 {
152 internal_update_settings__host(record.get_record_id(), std::move(field_value_of_host));
153 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(2), get_host(record));
154 }
155
156 void set_host(std::string field_value_of_host)
157 {
158 set_host(the_settings(), std::move(field_value_of_host));
159 }
160
161 void set_user(id_of_settings record, std::string field_value_of_user)
162 {
163 internal_update_settings__user(record.get_record_id(), std::move(field_value_of_user));
164 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(3), get_user(record));
165 }
166
167 void set_user(std::string field_value_of_user)
168 {
169 set_user(the_settings(), std::move(field_value_of_user));
170 }
171
172
173 };}
174
175#endif
void insert_into(Table_Id table_id, Record_Id record_id) override
Handle concurrent access to a joedb::Abstract_File using a joedb::Connection.
Definition Client.h:44
void comment(const std::string &comment) override
void timestamp(int64_t timestamp) override
static constexpr id_of_settings the_settings()
Definition Database.h:202
void internal_update_settings__dark_mode(Record_Id record_id, bool field_value_of_dark_mode)
Definition Database.h:111
void internal_insert_settings(Record_Id record_id)
Definition Database.h:99
void internal_update_settings__host(Record_Id record_id, std::string field_value_of_host)
Definition Database.h:134
const std::string & get_host(id_of_settings record=id_of_settings{0}) const
Definition Database.h:213
const std::string & get_user(id_of_settings record=id_of_settings{0}) const
Definition Database.h:219
void internal_update_settings__user(Record_Id record_id, std::string field_value_of_user)
Definition Database.h:157
detail::data_of_settings storage_of_settings
Definition Database.h:87
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_dark_mode(id_of_settings record, bool field_value_of_dark_mode)
void set_dark_mode(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
joedb::Blob write_blob(std::string_view data) override
void set_user(std::string field_value_of_user)
void set_host(id_of_settings record, std::string field_value_of_host)
void set_user(id_of_settings record, std::string field_value_of_user)
void set_host(std::string field_value_of_host)
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
Automatically generated by joedbc.
Definition Client.h:19