Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedbi.cpp
Go to the documentation of this file.
7
8#include <iostream>
9#include <optional>
10
11namespace joedb
12{
13 /////////////////////////////////////////////////////////////////////////////
14 static int joedbi(int argc, char **argv)
15 /////////////////////////////////////////////////////////////////////////////
16 {
17 const bool default_only = false;
18 const bool include_shared = false;
19
20 File_Parser file_parser
21 (
23 default_only,
24 include_shared
25 );
26
27 if (argc <= 1)
28 {
29 std::cerr << "usage: " << argv[0] << " <file> [<blob_file>]\n\n";
30 file_parser.print_help(std::cerr);
31 return 1;
32 }
33
34 int arg_index = 1;
35
36 std::ostream null_stream(nullptr);
37 Buffered_File &file = *file_parser.parse(null_stream, argc, argv, arg_index);
38
39 std::optional<File_Parser> blob_file_parser;
40 Buffered_File *blob_file = nullptr;
41
42 if (arg_index < argc)
43 {
44 blob_file_parser.emplace();
45 blob_file = blob_file_parser->parse(null_stream, argc, argv, arg_index);
46 }
47 else
48 blob_file = &file;
49
50 if (file.is_readonly() || (blob_file && blob_file->is_readonly()))
51 {
52 Database db;
53 Readonly_Journal journal(file);
54 journal.replay_log(db);
55 Readable_Interpreter interpreter(db, blob_file);
56 interpreter.main_loop(std::cin, std::cout);
57 }
58 else
59 {
60 Connection connection;
61 Writable_Database_Client client(file, connection);
62
63 std::optional<Writable_Journal> blob_journal;
64 if (blob_file_parser)
65 {
66 blob_journal.emplace(*blob_file);
67 blob_journal->append();
68 }
69
70 client.transaction([blob_file, &blob_journal]
71 (
72 const Readable &readable,
73 Writable &writable
74 )
75 {
76 Writable &blob_writer = blob_journal ? *blob_journal : writable;
77 Interpreter interpreter(readable, writable, blob_file, blob_writer, 0);
78 interpreter.main_loop(std::cin, std::cout);
79 if (blob_journal)
80 blob_journal->default_checkpoint();
81 });
82 }
83
84 return 0;
85 }
86}
87
88/////////////////////////////////////////////////////////////////////////////
89int main(int argc, char **argv)
90/////////////////////////////////////////////////////////////////////////////
91{
92 return joedb::main_exception_catcher(joedb::joedbi, argc, argv);
93}
int main()
@ write_existing_or_create_new
either write_existing or create_new depending on whether the file exists. Racy in Posix,...
int main_exception_catcher(int(*main)(int, char **), int argc, char **argv)
Catch exception from main.
Definition Blob.h:7