Joedb 9.1.4
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 checkpoint [no|half|full]
28 write_blob <data_string>
29
30)RRR";
31
32 return Status::ok;
33 }
34 else if (command == "comment") ///////////////////////////////////////////
35 {
36 const std::string comment = read_string(parameters);
37 writable.comment(comment);
38 }
39 else if (command == "timestamp") /////////////////////////////////////////
40 {
41 int64_t timestamp = 0;
42 parameters >> timestamp;
43 if (parameters.fail())
44 timestamp = std::time(nullptr);
45 writable.timestamp(timestamp);
46 }
47 else if (command == "valid_data") ////////////////////////////////////////
48 {
49 writable.valid_data();
50 }
51 else if (command == "flush") /////////////////////////////////////////////
52 {
53 writable.flush();
54 }
55 else if (command == "checkpoint") ////////////////////////////////////////
56 {
57 std::string param;
58 parameters >> param;
59
60 if (param == "no")
61 writable.checkpoint(Commit_Level::no_commit);
62 else if (param == "half")
63 writable.checkpoint(Commit_Level::half_commit);
64 else if (param == "full")
65 writable.checkpoint(Commit_Level::full_commit);
66 else if (param.empty())
67 writable.default_checkpoint();
68 else
69 out << "Error: unknown parameter: " << param << '\n';
70 }
71 else if (command == "write_blob") ////////////////////////////////////////
72 {
73 const std::string value = read_string(parameters);
74 const Blob blob = blob_writer.write_blob_data(value);
75 write_blob(out, blob);
76 out << '\n';
77 }
78 else
79 return Status::not_found;
80
81 return Status::done;
82 }
83}
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