Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Readable.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 tutorial_Readable_declared
13#define tutorial_Readable_declared
14
15#include "Database.h"
16
19
20namespace tutorial
21{
22 /// Implement the @ref joedb::Readable interface for a compiled database
23 ///
24 /// This allows using a compiled database with tools such as the
25 /// command interpreter.
27 {
28 private:
29 const Database &db;
30
31 public:
32 Readable(const Database &db): db(db)
33 {
34 joedb::Readonly_Memory_File file(detail::schema_string, detail::schema_string_size);
35 joedb::Readonly_Journal journal(file);
36 journal.replay_log(*this);
37 }
38
40 (
41 Table_Id table_id
42 ) const override
43 {
44 if (table_id == Table_Id{1})
45 return db.storage_of_city.freedom_keeper;
46 if (table_id == Table_Id{2})
47 return db.storage_of_person.freedom_keeper;
48
49 throw joedb::Exception("unknown table_id");
50 }
51
52 const std::string& get_string
53 (
54 Table_Id table_id,
55 Record_Id record_id,
56 Field_Id field_id
57 ) const override
58 {
59 if (table_id == Table_Id{1})
60 {
61 if (field_id == Field_Id(1))
62 {
63 return db.storage_of_city.field_value_of_name[size_t(record_id) - 1];
64 }
65 }
66
67 if (table_id == Table_Id{2})
68 {
69 if (field_id == Field_Id(1))
70 {
71 return db.storage_of_person.field_value_of_first_name[size_t(record_id) - 1];
72 }
73 if (field_id == Field_Id(2))
74 {
75 return db.storage_of_person.field_value_of_last_name[size_t(record_id) - 1];
76 }
77 }
78
79 throw joedb::Exception("unknown field");
80 }
81
82 const int32_t& get_int32
83 (
84 Table_Id table_id,
85 Record_Id record_id,
86 Field_Id field_id
87 ) const override
88 {
89 throw joedb::Exception("unknown field");
90 }
91
92 const int64_t& get_int64
93 (
94 Table_Id table_id,
95 Record_Id record_id,
96 Field_Id field_id
97 ) const override
98 {
99 throw joedb::Exception("unknown field");
100 }
101
103 (
104 Table_Id table_id,
105 Record_Id record_id,
106 Field_Id field_id
107 ) const override
108 {
109 if (table_id == Table_Id{2})
110 {
111 if (field_id == Field_Id(3))
112 {
113 return *reinterpret_cast<const joedb::Record_Id *>(&db.storage_of_person.field_value_of_home[size_t(record_id) - 1]);
114 }
115 }
116
117 throw joedb::Exception("unknown field");
118 }
119
120 const char& get_boolean
121 (
122 Table_Id table_id,
123 Record_Id record_id,
124 Field_Id field_id
125 ) const override
126 {
127 throw joedb::Exception("unknown field");
128 }
129
130 const float& get_float32
131 (
132 Table_Id table_id,
133 Record_Id record_id,
134 Field_Id field_id
135 ) const override
136 {
137 throw joedb::Exception("unknown field");
138 }
139
140 const double& get_float64
141 (
142 Table_Id table_id,
143 Record_Id record_id,
144 Field_Id field_id
145 ) const override
146 {
147 throw joedb::Exception("unknown field");
148 }
149
150 const int8_t& get_int8
151 (
152 Table_Id table_id,
153 Record_Id record_id,
154 Field_Id field_id
155 ) const override
156 {
157 throw joedb::Exception("unknown field");
158 }
159
160 const int16_t& get_int16
161 (
162 Table_Id table_id,
163 Record_Id record_id,
164 Field_Id field_id
165 ) const override
166 {
167 throw joedb::Exception("unknown field");
168 }
169
171 (
172 Table_Id table_id,
173 Record_Id record_id,
174 Field_Id field_id
175 ) const override
176 {
177 throw joedb::Exception("unknown field");
178 }
179 };
180
181 namespace interpreted_city
182 {
183 constexpr static Table_Id table_id = Table_Id{1};
184 constexpr static Field_Id name_field_id = Field_Id{1};
185 }
186
187 namespace interpreted_person
188 {
189 constexpr static Table_Id table_id = Table_Id{2};
190 constexpr static Field_Id first_name_field_id = Field_Id{1};
191 constexpr static Field_Id last_name_field_id = Field_Id{2};
192 constexpr static Field_Id home_field_id = Field_Id{3};
193 }
194}
195
196#endif
void replay_log(Writable &writable)
Store all the tables of the database.
Definition Database.h:101
detail::data_of_city storage_of_city
Definition Database.h:128
detail::data_of_person storage_of_person
Definition Database.h:130
Implement the joedb::Readable interface for a compiled database.
Definition Readable.h:27
const joedb::Blob & get_blob(Table_Id table_id, Record_Id record_id, Field_Id field_id) const override
Definition Readable.h:171
const joedb::Record_Id & get_reference(Table_Id table_id, Record_Id record_id, Field_Id field_id) const override
Definition Readable.h:103
const int64_t & get_int64(Table_Id table_id, Record_Id record_id, Field_Id field_id) const override
Definition Readable.h:93
const joedb::Compact_Freedom_Keeper & get_freedom(Table_Id table_id) const override
Definition Readable.h:40
const double & get_float64(Table_Id table_id, Record_Id record_id, Field_Id field_id) const override
Definition Readable.h:141
const int8_t & get_int8(Table_Id table_id, Record_Id record_id, Field_Id field_id) const override
Definition Readable.h:151
Readable(const Database &db)
Definition Readable.h:32
const float & get_float32(Table_Id table_id, Record_Id record_id, Field_Id field_id) const override
Definition Readable.h:131
const char & get_boolean(Table_Id table_id, Record_Id record_id, Field_Id field_id) const override
Definition Readable.h:121
const int32_t & get_int32(Table_Id table_id, Record_Id record_id, Field_Id field_id) const override
Definition Readable.h:83
const int16_t & get_int16(Table_Id table_id, Record_Id record_id, Field_Id field_id) const override
Definition Readable.h:161
const std::string & get_string(Table_Id table_id, Record_Id record_id, Field_Id field_id) const override
Definition Readable.h:53
Automatically generated by joedbc.
Definition Client.h:19