Joedb 10.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_logdump.cpp
Go to the documentation of this file.
2#include "joedb/Multiplexer.h"
11
12#include <iostream>
13#include <memory>
14#include <optional>
15
16namespace joedb
17{
18 /////////////////////////////////////////////////////////////////////////////
19 static void dump
20 /////////////////////////////////////////////////////////////////////////////
21 (
22 Readonly_Journal &journal,
23 Writable &writable,
24 bool print_checkpoint
25 )
26 {
27 if (print_checkpoint)
28 journal.replay_with_checkpoint_comments(writable);
29 else
30 journal.replay_log(writable);
31 }
32
33 /////////////////////////////////////////////////////////////////////////////
34 static int logdump(Arguments &arguments)
35 /////////////////////////////////////////////////////////////////////////////
36 {
37 const bool sql = arguments.has_flag("sql");
38 const bool raw = arguments.has_flag("raw");
39 const bool header = arguments.has_flag("header");
40 const bool schema_only = arguments.has_flag("schema_only");
41 const bool ignore_header = arguments.has_flag("ignore_header");
42 const bool load = arguments.has_flag("load");
43 const bool print_checkpoint = arguments.has_flag("print_checkpoint");
44 const bool blob = arguments.has_flag("blob");
45 const beman::cstring_view file_name = arguments.get_next("file.joedb");
46
47 if (arguments.missing())
48 {
49 arguments.print_help(std::cerr);
50 return 1;
51 }
52
53 File file(file_name.c_str(), Open_Mode::read_existing);
54
55 if (header)
56 dump_header(std::cout, file);
57 else
58 {
59 std::optional<Readonly_Journal> journal;
60
61 journal.emplace
62 (
64 (
65 file,
67 )
68 );
69
70 std::unique_ptr<Writable> writable;
71
72 const Abstract_File *blob_reader = blob ? &file : nullptr;
73
74 if (sql)
75 writable.reset(new SQL_Dump_Writable(std::cout, blob_reader));
76 else if (raw)
77 writable.reset(new Raw_Dump_Writable(std::cout));
78 else
79 writable.reset(new Interpreter_Dump_Writable(std::cout, blob));
80
81 if (schema_only)
82 {
83 Selective_Writable selective_writable
84 (
85 *writable,
87 );
88 journal->replay_log(selective_writable);
89 }
90 else if (load)
91 {
93 Multiplexer multiplexer{*writable, db};
94 dump(*journal, multiplexer, print_checkpoint);
95 }
96 else
97 dump(*journal, *writable, print_checkpoint);
98 }
99
100 return 0;
101 }
102}
103
104/////////////////////////////////////////////////////////////////////////////
105int main(int argc, char **argv)
106/////////////////////////////////////////////////////////////////////////////
107{
108 return joedb::main_wrapper(joedb::logdump, argc, argv);
109}
Class for conveniently parsing command-line arguments.
Definition Arguments.h:16
Superclass with all joedb journal event listeners as virtual functions.
Definition Writable.h:17
int main()
void dump_header(std::ostream &out, Abstract_File &file)
@ read_existing
fails if does not exist
Definition Open_Mode.h:9
@ none
default: fail if file size > checkpoint
@ ignore_header
use file size as checkpoint
int main_wrapper(int(*main)(Arguments &), int argc, char **argv)
Process command-line arguments and catch exceptions from main.
void dump(const Readable &db, Writable &writable, bool schema_only)
Definition dump.cpp:12
JOEDB_FILE File
Definition File.h:23