Joedb 9.5.0
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: 9.5.0
8// joedbc compilation time: May 5 2025 19:51:43
9// Generation of this file: 2025-05-05 17:51:47 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#ifndef joedb_db_encoded_file_Client_declared
13#define joedb_db_encoded_file_Client_declared
14
15#include "Writable_Database.h"
17
19{
20 namespace detail
21 {
22 ///////////////////////////////////////////////////////////////////////////
23 class Client_Data
24 ///////////////////////////////////////////////////////////////////////////
25 {
26 protected:
27 Writable_Database db;
28
29 Client_Data(joedb::Buffered_File &file): db(file, false)
30 {
31 }
32 };
33 }
34
35 /// Handle concurrent access to a @ref joedb::Buffered_File using a @ref joedb::Connection
36 class Client:
37 protected detail::Client_Data,
39 {
40 friend class Client_Lock;
41
42 private:
43 int64_t schema_checkpoint;
44
45 protected:
46 void read_journal() override
47 {
48 db.play_journal();
49 if (schema_checkpoint)
50 {
51 if (db.schema_journal.get_checkpoint() > schema_checkpoint)
52 Database::throw_exception("Can't upgrade schema during pull");
53 db.check_single_row();
54 }
55 }
56
57 public:
59 (
63 ):
64 detail::Client_Data(file),
65 joedb::Writable_Client(db.journal, connection, content_check),
66 schema_checkpoint(0)
67 {
70
71 db.play_journal(); // makes transaction shorter if db is big
73 db.initialize();
74 });
75
76 schema_checkpoint = db.schema_journal.get_checkpoint();
77 }
78
79 const Database &get_database() const
80 {
81 return db;
82 }
83
84 /// Execute a write transaction
85 ///
86 /// This function can be called with a lambda like this:
87 /// @code
88 /// client.transaction([](Writable_Database &db)
89 /// {
90 /// db.write_comment("Hello");
91 /// });
92 /// @endcode
93 /// The transaction function locks and pulls the connection before
94 /// executing the lambda, pushes and unlocks it after.
95 template<typename F> auto transaction
96 (
98 )
99 {
101 {
102 return transaction(db);
103 });
104 }
105 };
106
107 /// For more flexibility than the transaction lambda
108 ///
109 /// See joedb::Client_Lock for more information
110 ///
111 /// @include client_lock.cpp
113 {
114 public:
118
120 {
122 return static_cast<Client &>(client).db;
123 }
124 };
125}
126
127#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.
auto transaction(F transaction)
For more flexibility than the transaction lambda.
Definition Client.h:113
Writable_Database & get_database()
Definition Client.h:119
Handle concurrent access to a joedb::Buffered_File using a joedb::Connection.
Definition Client.h:39
void read_journal() override
Definition Client.h:46
const Database & get_database() const
Definition Client.h:79
Client(joedb::Buffered_File &file, joedb::Connection &connection, joedb::Content_Check content_check=joedb::Content_Check::quick)
Definition Client.h:59
auto transaction(F transaction)
Execute a write transaction.
Definition Client.h:96
Store all the tables of the database.
Definition Database.h:75
static void throw_exception(const std::string &message)
Definition Database.h:82
A writable Database constructed from a writable joedb::Buffered_File.
Content_Check
Definition Connection.h:19
#define JOEDB_DEBUG_ASSERT(x)
Definition assert.h:20
Automatically generated by joedbc.
Definition Client.h:19
Definition Blob.h:7