Joedb 9.1.4
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/doc/source/tutorial/build/joedbc
7// Version: 9.1.4
8// joedbc compilation time: Apr 15 2025 14:46:29
9// Generation of this file: 2025-04-15 12:46:31 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 (
33 joedb::Commit_Level commit_level
34 ):
35 db(file, false, check, commit_level)
36 {
37 }
38 };
39 }
40
41 /// Handle concurrent access to a @ref joedb::Buffered_File using a @ref joedb::Connection
42 class Client:
43 protected detail::Client_Data,
44 public joedb::Client
45 {
46 friend class Client_Lock;
47
48 private:
49 int64_t schema_checkpoint;
50
51 protected:
52 void read_journal() override
53 {
54 db.play_journal();
55 if (schema_checkpoint)
56 {
57 if (db.schema_journal.get_checkpoint_position() > schema_checkpoint)
58 Database::throw_exception("Can't upgrade schema during pull");
59 db.check_single_row();
60 }
61 }
62
63 public:
65 (
67 joedb::Connection &connection,
68 bool content_check = true,
71 ):
72 detail::Client_Data(file, check, commit_level),
73 joedb::Client(db.journal, connection, content_check),
74 schema_checkpoint(0)
75 {
78
79 db.play_journal(); // makes transaction shorter if db is big
81 db.initialize();
82 });
83
84 schema_checkpoint = db.schema_journal.get_checkpoint_position();
85 }
86
87 const Database &get_database() const
88 {
89 return db;
90 }
91
92 /// Execute a write transaction
93 ///
94 /// This function can be called with a lambda like this:
95 /// @code
96 /// client.transaction([](Writable_Database &db)
97 /// {
98 /// db.write_comment("Hello");
99 /// });
100 /// @endcode
101 /// The transaction function locks and pulls the connection before
102 /// executing the lambda, pushes and unlocks it after.
103 template<typename F> void transaction
104 (
106 )
107 {
109 {
110 transaction(db);
111 });
112 }
113 };
114
115 /// For more flexibility than the transaction lambda
116 ///
117 /// See joedb::Client_Lock for more information
118 ///
119 /// @include client_lock.cpp
121 {
122 public:
126
128 {
130 return static_cast<Client &>(client).db;
131 }
132 };
133}
134
135#endif
Lock object that allows writing to a database managed by a joedb::Client.
Definition Client.h:161
bool is_locked() const
Definition Client.h:168
Client & client
Definition Client.h:166
Handle concurrent access to a file with a joedb::Connection.
Definition Client.h:12
void transaction(F transaction)
Definition Client.h:18
int64_t get_checkpoint_difference() const
Definition Client.h:116
void push_unlock()
Definition Client.h:143
For more flexibility than the transaction lambda.
Definition Client.h:121
Writable_Database & get_database()
Definition Client.h:127
Client_Lock(Client &client)
Definition Client.h:123
Handle concurrent access to a joedb::Buffered_File using a joedb::Connection.
Definition Client.h:45
const Database & get_database() const
Definition Client.h:87
void transaction(F transaction)
Execute a write transaction.
Definition Client.h:104
void read_journal() override
Definition Client.h:52
Client(joedb::Buffered_File &file, joedb::Connection &connection, bool content_check=true, joedb::Readonly_Journal::Check check=joedb::Readonly_Journal::Check::all, joedb::Commit_Level commit_level=joedb::Commit_Level::no_commit)
Definition Client.h:65
Store all the tables of the database.
Definition Database.h:76
static void throw_exception(const std::string &message)
Definition Database.h:83
A writable Database constructed from a writable joedb::Buffered_File.
#define JOEDB_ASSERT(x)
Definition assert.h:18
Definition Blob.h:7
Commit_Level
Definition Writable.h:13
Automatically generated by joedbc.
Definition Client.h:19