Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Client.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_Client_declared
13#define settings_Client_declared
14
15#include "Writable_Database.h"
17
18namespace settings
19{
20 namespace detail
21 {
22 ///////////////////////////////////////////////////////////////////////////
23 class Client_Data
24 ///////////////////////////////////////////////////////////////////////////
25 {
26 protected:
28
29 Client_Data
30 (
32 joedb::Recovery recovery
33 ):
34 db(file, recovery, false)
35 {
36 }
37 };
38 }
39
40 /// Handle concurrent access to a @ref joedb::Buffered_File using a @ref joedb::Connection
41 class Client:
42 protected detail::Client_Data,
44 {
45 friend class Client_Lock;
46
47 private:
48 int64_t schema_checkpoint;
49
50 protected:
51 void read_journal() override
52 {
53 db.play_journal();
54 if (schema_checkpoint)
55 {
56 if (db.schema_journal.get_checkpoint() > schema_checkpoint)
57 Database::throw_exception("Can't upgrade schema during pull");
58 db.check_single_row();
59 }
60 }
61
62 public:
64 (
69 ):
70 detail::Client_Data(file, recovery),
71 joedb::Writable_Client(db.journal, connection, content_check),
72 schema_checkpoint(0)
73 {
76
77 db.play_journal(); // makes transaction shorter if db is big
79 db.initialize();
80 });
81
82 schema_checkpoint = db.schema_journal.get_checkpoint();
83 }
84
85 const Database &get_database() const
86 {
87 return db;
88 }
89
90 /// Execute a write transaction
91 ///
92 /// This function can be called with a lambda like this:
93 /// @code
94 /// client.transaction([](Writable_Database &db)
95 /// {
96 /// db.write_comment("Hello");
97 /// });
98 /// @endcode
99 /// The transaction function locks and pulls the connection before
100 /// executing the lambda, pushes and unlocks it after.
101 template<typename F> auto transaction
102 (
104 )
105 {
107 {
108 return transaction(db);
109 });
110 }
111 };
112
113 /// For more flexibility than the transaction lambda
114 ///
115 /// See joedb::Client_Lock for more information
116 ///
117 /// @include client_lock.cpp
119 {
120 public:
124
126 {
128 return static_cast<Client &>(client).db;
129 }
130 };
131}
132
133#endif
Lock object that allows writing to a database managed by a joedb::Client.
Writable_Client & client
Readonly_Journal & journal
Definition Client.h:15
Connection & connection
Definition Client.h:16
int64_t get_checkpoint_difference() const
Definition Client.h:77
Writable specialization of Client.
Writable_Client(Writable_Journal &journal, Connection &connection, Content_Check content_check=Content_Check::fast)
auto transaction(F transaction)
For more flexibility than the transaction lambda.
Definition Client.h:119
Writable_Database & get_database()
Definition Client.h:125
Client_Lock(Client &client)
Definition Client.h:121
Handle concurrent access to a joedb::Buffered_File using a joedb::Connection.
Definition Client.h:44
const Database & get_database() const
Definition Client.h:85
void read_journal() override
Definition Client.h:51
auto transaction(F transaction)
Execute a write transaction.
Definition Client.h:102
Client(joedb::Buffered_File &file, joedb::Connection &connection, joedb::Content_Check content_check=joedb::Content_Check::fast, joedb::Recovery recovery=joedb::Recovery::none)
Definition Client.h:64
Store all the tables of the database.
Definition Database.h:68
static void throw_exception(const std::string &message)
Definition Database.h:75
A Database that contains a joedb::Writable_Journal and keeps them in sync.
Content_Check
Definition Connection.h:19
#define JOEDB_DEBUG_ASSERT(x)
assertion tested in debug mode
Definition assert.h:19
@ none
default: fail if file size > checkpoint
Definition Blob.h:7
Automatically generated by joedbc.
Definition Client.h:19