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 tutorial_rpc_city_Writable_Database_declared
13#define tutorial_rpc_city_Writable_Database_declared
14
15#include "Database_Writable.h"
16
17#include <utility>
18
19namespace tutorial::rpc::city
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 create_table(const std::string &name) override;
48
49 Writable_Database
50 (
52 joedb::Recovery recovery,
53 bool perform_initialization
54 );
55
56 public:
57 Writable_Database(joedb::Abstract_File &file);
58
59 Writable_Database
60 (
62 joedb::Recovery recovery
63 );
64
65 const joedb::Readonly_Journal &get_journal() const {return journal;}
66
67 std::string read_blob(joedb::Blob blob) const
68 {
69 return journal.get_file().read_blob(blob);
70 }
71
72 joedb::Blob write_blob(std::string_view data) override
73 {
74 return journal.write_blob(data);
75 }
76
77 int64_t ahead_of_checkpoint() const
78 {
79 return journal.ahead_of_checkpoint();
80 }
81
82 void soft_checkpoint() override
83 {
84 journal.soft_checkpoint();
85 }
86
87 void hard_checkpoint() override
88 {
89 journal.hard_checkpoint();
90 }
91
92 void write_comment(const std::string &comment);
93 void write_timestamp();
94 void write_timestamp(int64_t timestamp);
95 void write_valid_data();
96 void flush() override {journal.flush();}
97
98 private:
99 id_of_city new_city()
100 {
101 id_of_city result(Record_Id(storage_of_city.freedom_keeper.get_free_record()));
102 storage_of_city.resize(storage_of_city.freedom_keeper.size());
103 internal_insert_city(result.get_record_id());
104
105 journal.insert_into(Table_Id(1), result.get_record_id());
106 return result;
107 }
108
109 void insert_city(id_of_city id)
110 {
111 if (id.get_record_id() >= Record_Id(storage_of_city.size()))
112 storage_of_city.resize(id.get_id() + 1);
113 internal_insert_city(id.get_record_id());
114 journal.insert_into(Table_Id(1), id.get_record_id());
115 }
116
117 id_of_city new_city
118 (
119 std::string field_value_of_name
120 )
121 {
122 auto result = new_city();
123 set_name(result, std::move(field_value_of_name));
124 return result;
125 }
126
127 public:
128 void set_name(id_of_city record, std::string field_value_of_name)
129 {
130 internal_update_city__name(record.get_record_id(), std::move(field_value_of_name));
131 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(1), get_name(record));
132 }
133
134 void set_name(std::string field_value_of_name)
135 {
136 set_name(the_city(), std::move(field_value_of_name));
137 }
138
139
140 };}
141
142#endif
void insert_into(Table_Id table_id, Record_Id record_id) override
Strongly-typed wrapper around an integer representing a row of the city table.
Definition ids.h:25
constexpr Record_Id get_record_id() const
Definition ids.h:36
Handle concurrent access to a joedb::Abstract_File using a joedb::Connection.
Definition Client.h:44
void timestamp(int64_t timestamp) override
void comment(const std::string &comment) override
void internal_insert_city(Record_Id record_id)
Definition Database.h:92
static constexpr id_of_city the_city()
Definition Database.h:149
const std::string & get_name(id_of_city record=id_of_city{0}) const
Definition Database.h:154
detail::data_of_city storage_of_city
Definition Database.h:82
void internal_update_city__name(Record_Id record_id, std::string field_value_of_name)
Definition Database.h:104
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
std::string read_blob(joedb::Blob blob) const
void set_name(id_of_city record, std::string field_value_of_name)
void set_name(std::string field_value_of_name)
joedb::Blob write_blob(std::string_view data) override
const joedb::Readonly_Journal & get_journal() const
void write_comment(const std::string &comment)
Automatically generated by joedbc.
Definition Client.h:19
tutorial::id_of_city id_of_city
Definition ids.h:23