Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Writable_Command_Processor.cpp
Go to the documentation of this file.
2#include "joedb/ui/type_io.h"
3#include "joedb/Writable.h"
4
5#include <ctime>
6
7namespace joedb
8{
9 ////////////////////////////////////////////////////////////////////////////
10 Command_Processor::Status Writable_Command_Processor::process_command
11 ////////////////////////////////////////////////////////////////////////////
12 (
13 const std::string &command,
14 std::istream &parameters,
15 std::istream &in,
16 std::ostream &out
17 )
18 {
19 if (command == "help") ////////////////////////////////////////////////////
20 {
21 out << R"RRR(Journal
22~~~~~~~
23 timestamp [<stamp>] (if no value is given, use current time)
24 comment "<comment_string>"
25 valid_data
26 flush
27 [soft_]checkpoint
28 hard_checkpoint
29 write_blob <data_string>
30
31)RRR";
32
33 return Status::ok;
34 }
35 else if (command == "comment") ///////////////////////////////////////////
36 {
37 const std::string comment = read_string(parameters);
38 writable.comment(comment);
39 }
40 else if (command == "timestamp") /////////////////////////////////////////
41 {
42 int64_t timestamp = 0;
43 parameters >> timestamp;
44 if (parameters.fail())
45 timestamp = std::time(nullptr);
46 writable.timestamp(timestamp);
47 }
48 else if (command == "valid_data") ////////////////////////////////////////
49 {
50 writable.valid_data();
51 }
52 else if (command == "flush") /////////////////////////////////////////////
53 {
54 writable.flush();
55 }
56 else if (command == "soft_checkpoint" || command == "checkpoint") ////////
57 {
58 writable.soft_checkpoint();
59 }
60 else if (command == "hard_checkpoint") ///////////////////////////////////
61 {
62 writable.hard_checkpoint();
63 }
64 else if (command == "write_blob") ////////////////////////////////////////
65 {
66 const std::string value = read_string(parameters);
67 const Blob blob = blob_writer.write_blob(value);
68 write_blob(out, blob);
69 out << '\n';
70 }
71 else
72 return Status::not_found;
73
74 return Status::done;
75 }
76}
void write_blob(std::ostream &out, Blob blob)
Definition type_io.cpp:243
std::string read_string(std::istream &in)
Definition type_io.cpp:12
Definition Blob.h:7