Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Raw_Dump_Writable.cpp
Go to the documentation of this file.
2#include "joedb/ui/type_io.h"
3
4#include <iostream>
5
6namespace joedb
7{
8 ////////////////////////////////////////////////////////////////////////////
9 void Raw_Dump_Writable::write_type(Type type)
10 ////////////////////////////////////////////////////////////////////////////
11 {
12 switch(type.get_type_id())
13 {
15 out << "null";
16 break;
17
18 #define TYPE_MACRO(type, return_type, type_id, read, write)\
19 case Type::Type_Id::type_id:\
20 out << #type_id;\
21 break;
22 #define TYPE_MACRO_NO_REFERENCE
23 #include "joedb/TYPE_MACRO.h"
24
25 case Type::Type_Id::reference:
26 out << "references " << type.get_table_id();
27 break;
28 }
29 }
30
31 ////////////////////////////////////////////////////////////////////////////
32 void Raw_Dump_Writable::create_table(const std::string &name)
33 ////////////////////////////////////////////////////////////////////////////
34 {
35 out << "create_table ";
36 write_string(out, name);
37 out << '\n';
38 }
39
40 ////////////////////////////////////////////////////////////////////////////
42 ////////////////////////////////////////////////////////////////////////////
43 {
44 out << "drop_table " << table_id << '\n';
45 }
46
47 ////////////////////////////////////////////////////////////////////////////
49 ////////////////////////////////////////////////////////////////////////////
50 (
51 Table_Id table_id,
52 const std::string &name
53 )
54 {
55 out << "rename_table " << table_id << ' ';
56 write_string(out, name);
57 out << '\n';
58 }
59
60 ////////////////////////////////////////////////////////////////////////////
62 (
63 Table_Id table_id,
64 const std::string &name,
65 Type type
66 )
67 ////////////////////////////////////////////////////////////////////////////
68 {
69 out << "add_field " << table_id << ' ';
70 write_string(out, name);
71 out << ' ';
72 write_type(type);
73 out << '\n';
74 }
75
76 ////////////////////////////////////////////////////////////////////////////
78 ////////////////////////////////////////////////////////////////////////////
79 {
80 out << "drop_field " << table_id << ' ' << field_id << '\n';
81 }
82
83 ////////////////////////////////////////////////////////////////////////////
85 ////////////////////////////////////////////////////////////////////////////
86 (
87 Table_Id table_id,
88 Field_Id field_id,
89 const std::string &name
90 )
91 {
92 out << "rename_field " << table_id << ' ';
93 out << field_id << ' ';
94 write_string(out, name);
95 out << '\n';
96 }
97
98 ////////////////////////////////////////////////////////////////////////////
99 void Raw_Dump_Writable::custom(const std::string &name)
100 ////////////////////////////////////////////////////////////////////////////
101 {
102 out << "custom ";
103 write_string(out, name);
104 out << '\n';
105 }
106
107 ////////////////////////////////////////////////////////////////////////////
108 void Raw_Dump_Writable::comment(const std::string &comment)
109 ////////////////////////////////////////////////////////////////////////////
110 {
111 out << "comment ";
112 write_string(out, comment);
113 out << '\n';
114 }
115
116 ////////////////////////////////////////////////////////////////////////////
117 void Raw_Dump_Writable::timestamp(int64_t timestamp)
118 ////////////////////////////////////////////////////////////////////////////
119 {
120 out << "timestamp " << timestamp << '\n';
121 }
122
123 ////////////////////////////////////////////////////////////////////////////
125 ////////////////////////////////////////////////////////////////////////////
126 {
127 out << "valid_data\n";
128 }
129
130 ////////////////////////////////////////////////////////////////////////////
132 ////////////////////////////////////////////////////////////////////////////
133 {
134 out << "insert_into " << table_id << ' ' << record_id << '\n';
135 }
136
137 ////////////////////////////////////////////////////////////////////////////
139 ////////////////////////////////////////////////////////////////////////////
140 (
141 Table_Id table_id,
142 Record_Id record_id,
143 size_t size
144 )
145 {
146 out << "insert_vector " << table_id << ' ';
147 out << record_id << ' ' << size << '\n';
148 }
149
150 ////////////////////////////////////////////////////////////////////////////
152 ////////////////////////////////////////////////////////////////////////////
153 {
154 out << "delete_from " << table_id << ' ';
155 out << record_id << '\n';
156 }
157
158 #define TYPE_MACRO(type, return_type, type_id, R, W)\
159 void Raw_Dump_Writable::update_##type_id\
160 (\
161 Table_Id table_id,\
162 Record_Id record_id,\
163 Field_Id field_id,\
164 return_type value\
165 )\
166 {\
167 out << "update_" << #type_id << ' ' << table_id << ' ';\
168 out << record_id << ' ';\
169 out << field_id << ' ';\
170 joedb::write_##type_id(out, value);\
171 out << '\n';\
172 }\
173 void Raw_Dump_Writable::update_vector_##type_id\
174 (\
175 Table_Id table_id,\
176 Record_Id record_id,\
177 Field_Id field_id,\
178 size_t size,\
179 const type *value\
180 )\
181 {\
182 out << "update_vector_" << #type_id << ' ' << table_id << ' ';\
183 out << record_id << ' ';\
184 out << field_id << ' ';\
185 out << size;\
186 for (size_t i = 0; i < size; i++)\
187 {\
188 out << ' ';\
189 joedb::write_##type_id(out, value[i]);\
190 }\
191 out << '\n';\
192 }
193 #include "joedb/TYPE_MACRO.h"
194
195 ////////////////////////////////////////////////////////////////////////////
197 ////////////////////////////////////////////////////////////////////////////
198 {
199 out << "write_blob ";
200 joedb::write_string(out, data);
201 out << '\n';
202 return Blob();
203 }
204
205 ////////////////////////////////////////////////////////////////////////////
207 ////////////////////////////////////////////////////////////////////////////
208}
void comment(const std::string &comment) final
void rename_field(Table_Id table_id, Field_Id field_id, const std::string &name) final
void delete_from(Table_Id table_id, Record_Id record_id) final
void create_table(const std::string &name) final
void drop_table(Table_Id table_id) final
void insert_into(Table_Id table_id, Record_Id record_id) final
void add_field(Table_Id table_id, const std::string &name, Type type) final
void timestamp(int64_t timestamp) final
void drop_field(Table_Id table_id, Field_Id field_id) final
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) final
void rename_table(Table_Id table_id, const std::string &name) final
Blob write_blob_data(const std::string &data) final
void custom(const std::string &name) final
void write_string(std::ostream &out, const std::string &s, bool json)
Definition Blob.h:7