Joedb 10.4.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.4.1
8// joedbc compilation time: Apr 22 2026 15:39:07
9// Generation of this file: 2026-04-22 13:39:40 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#ifndef settings_Writable_Database_declared
13#define settings_Writable_Database_declared
14
15#include "Database_Writable.h"
16
17namespace settings
18{
19 namespace detail
20 {
21 class Client_Data;
22 }
23
24 class Client;
25 class Multiplexer;
26 class Memory_Database;
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 friend class Memory_Database;
35
36 private:
38 bool ready_to_write;
39
40 void play_journal();
41 void auto_upgrade();
42 void check_single_row();
43 void initialize();
44
45 void add_field
46 (
47 Table_Id table_id,
48 const std::string &name,
49 joedb::Type type
50 ) override;
51
52 void create_table(const std::string &name) override;
53
55 (
57 joedb::Recovery recovery,
58 bool perform_initialization
59 );
60
61 public:
63
65 (
67 joedb::Recovery recovery
68 );
69
70 const joedb::Readonly_Journal &get_journal() const {return journal;}
71
72 std::string read_blob(joedb::Blob blob) const
73 {
74 return journal.get_file().read_blob(blob);
75 }
76
77 joedb::Blob write_blob(std::string_view data) override
78 {
79 return journal.write_blob(data);
80 }
81
82 int64_t ahead_of_checkpoint() const
83 {
84 return journal.ahead_of_checkpoint();
85 }
86
87 void soft_checkpoint() override
88 {
89 journal.soft_checkpoint();
90 }
91
92 void hard_checkpoint() override
93 {
94 journal.hard_checkpoint();
95 }
96
97 void write_comment(const std::string &comment);
98 void write_timestamp();
99 void write_timestamp(int64_t timestamp);
100 void write_valid_data();
101 void flush() override {journal.flush();}
102
103 private:
104 id_of_settings new_settings()
105 {
106 id_of_settings result(Record_Id(storage_of_settings.freedom_keeper.get_free_record()));
107 storage_of_settings.resize(storage_of_settings.freedom_keeper.size());
108 internal_insert_settings(result.get_record_id());
109
110 journal.insert_into(Table_Id(1), result.get_record_id());
111 return result;
112 }
113
114 void insert_settings(id_of_settings id)
115 {
116 if (id.get_record_id() >= Record_Id(storage_of_settings.size()))
117 storage_of_settings.resize(id.get_id() + 1);
118 internal_insert_settings(id.get_record_id());
119 journal.insert_into(Table_Id(1), id.get_record_id());
120 }
121
122 id_of_settings new_settings
123 (
124 bool field_value_of_dark_mode,
125 std::string_view field_value_of_host,
126 std::string_view field_value_of_user
127 )
128 {
129 auto result = new_settings();
130 set_dark_mode(result, field_value_of_dark_mode);
131 set_host(result, field_value_of_host);
132 set_user(result, field_value_of_user);
133 return result;
134 }
135
136 public:
137 void set_dark_mode(id_of_settings record, bool field_value_of_dark_mode)
138 {
139 internal_update_settings__dark_mode(record.get_record_id(), field_value_of_dark_mode);
140 journal.update_boolean(Table_Id(1), record.get_record_id(), Field_Id(1), field_value_of_dark_mode);
141 }
142
143 void set_dark_mode(bool field_value_of_dark_mode)
144 {
145 set_dark_mode(the_settings(), field_value_of_dark_mode);
146 }
147
148 void set_host(id_of_settings record, std::string_view field_value_of_host)
149 {
150 internal_update_settings__host(record.get_record_id(), field_value_of_host);
151 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(2), field_value_of_host);
152 }
153
154 void set_host(std::string_view field_value_of_host)
155 {
156 set_host(the_settings(), field_value_of_host);
157 }
158
159 void set_user(id_of_settings record, std::string_view field_value_of_user)
160 {
161 internal_update_settings__user(record.get_record_id(), field_value_of_user);
162 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(3), field_value_of_user);
163 }
164
165 void set_user(std::string_view field_value_of_user)
166 {
167 set_user(the_settings(), field_value_of_user);
168 }
169
170
171 };}
172
173#endif
std::string read_blob(Blob blob) const
const Abstract_File & get_file() const
int64_t ahead_of_checkpoint() const noexcept
void insert_into(Table_Id table_id, Record_Id record_id) override
Blob write_blob(std::string_view data) override
Handle concurrent access to a joedb::Abstract_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
static constexpr id_of_settings the_settings()
Definition Database.h:199
void internal_update_settings__dark_mode(Record_Id record_id, bool field_value_of_dark_mode)
Definition Database.h:108
void internal_insert_settings(Record_Id record_id)
Definition Database.h:96
void internal_update_settings__user(Record_Id record_id, std::string_view field_value_of_user)
Definition Database.h:154
void internal_update_settings__host(Record_Id record_id, std::string_view field_value_of_host)
Definition Database.h:131
detail::data_of_settings storage_of_settings
Definition Database.h:84
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
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 set_dark_mode(bool field_value_of_dark_mode)
void set_host(id_of_settings record, std::string_view field_value_of_host)
void write_comment(const std::string &comment)
std::string read_blob(joedb::Blob blob) const
const joedb::Readonly_Journal & get_journal() const
void set_user(std::string_view field_value_of_user)
joedb::Blob write_blob(std::string_view data) override
void set_host(std::string_view field_value_of_host)
void set_user(id_of_settings record, std::string_view field_value_of_user)
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