Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Writable_Database.cpp
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#include "Writable_Database.h"
13#include "joedb/Writable.h"
15
16#include <ctime>
17
18namespace tutorial
19{
20 ////////////////////////////////////////////////////////////////////////////
21 void Writable_Database::write_comment(const std::string &comment)
22 ////////////////////////////////////////////////////////////////////////////
23 {
24 journal.comment(comment);
25 }
26
27 ////////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////////
30 {
31 journal.timestamp(std::time(nullptr));
32 }
33
34 ////////////////////////////////////////////////////////////////////////////
35 void Writable_Database::write_timestamp(int64_t timestamp)
36 ////////////////////////////////////////////////////////////////////////////
37 {
38 journal.timestamp(timestamp);
39 }
40
41 ////////////////////////////////////////////////////////////////////////////
43 ////////////////////////////////////////////////////////////////////////////
44 {
45 journal.valid_data();
46 }
47
48 ////////////////////////////////////////////////////////////////////////////
49 void Writable_Database::play_journal()
50 ////////////////////////////////////////////////////////////////////////////
51 {
52 max_record_id = size_t(journal.get_checkpoint());
53 ready_to_write = false;
54 journal.play_until_checkpoint(*this);
55 ready_to_write = true;
56 max_record_id = 0;
57 }
58
59 ////////////////////////////////////////////////////////////////////////////
60 void Writable_Database::auto_upgrade()
61 ////////////////////////////////////////////////////////////////////////////
62 {
63 const size_t file_schema_size = size_t(schema_file.get_size());
64
65 if (file_schema_size < detail::schema_string_size)
66 {
67 journal.comment("Automatic schema upgrade");
68
69 joedb::Readonly_Memory_File schema_file(detail::schema_string, detail::schema_string_size);
71
72 schema_journal.skip_directly_to(int64_t(file_schema_size));
73 schema_journal.append_until(journal, detail::schema_string_size);
74
75 schema_journal.skip_directly_to(int64_t(file_schema_size));
76 upgrading_schema = true;
77 schema_journal.append_until(*this, detail::schema_string_size);
78 upgrading_schema = false;
79
80 journal.valid_data();
81 journal.soft_checkpoint();
82 }
83 }
84
85 ////////////////////////////////////////////////////////////////////////////
86 Writable_Database::Writable_Database
87 ////////////////////////////////////////////////////////////////////////////
88 (
90 bool perform_initialization
91 ):
92 journal(file)
93 {
94 journal.rewind();
95
96 if (perform_initialization)
97 initialize();
98 }
99
100 ////////////////////////////////////////////////////////////////////////////
101 Writable_Database::Writable_Database(joedb::Buffered_File &file):
102 ////////////////////////////////////////////////////////////////////////////
103 Writable_Database(file, true)
104 {
105 }
106
107 ////////////////////////////////////////////////////////////////////////////
108 void Writable_Database::check_single_row()
109 ////////////////////////////////////////////////////////////////////////////
110 {
111 }
112
113 /////////////////////////////////////////////////////////////////////////////
115 /////////////////////////////////////////////////////////////////////////////
116 {
117 while (!get_city_table().is_empty())
118 delete_city(get_city_table().last());
119 }
120
121 /////////////////////////////////////////////////////////////////////////////
123 /////////////////////////////////////////////////////////////////////////////
124 {
125 while (!get_person_table().is_empty())
127 }
128}
int64_t get_size() const override
Get the size of the file, or -1 if it is unknown.
Definition Memory_File.h:24
void append_until(Writable &writable, int64_t end)
void play_until_checkpoint(Writable &writable)
int64_t get_checkpoint() const
void skip_directly_to(int64_t position)
void timestamp(int64_t timestamp) final
void comment(const std::string &comment) final
void soft_checkpoint()
Definition Writable.h:21
container_of_person get_person_table() const
Definition Database.h:908
void comment(const std::string &comment) override
Definition Database.h:577
void timestamp(int64_t timestamp) override
Definition Database.h:578
joedb::Memory_File schema_file
Definition Database.h:582
container_of_city get_city_table() const
Definition Database.h:850
joedb::Writable_Journal schema_journal
Definition Database.h:583
A writable Database constructed from a writable joedb::Buffered_File.
void write_comment(const std::string &comment)
void delete_city(id_of_city record)
void delete_person(id_of_person record)
Automatically generated by joedbc.
Definition Client.h:19