Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedbi.cpp
Go to the documentation of this file.
7
8#include <iostream>
9
10namespace joedb
11{
12 ////////////////////////////////////////////////////////////////////////////
13 static int joedbi(Arguments &arguments)
14 ////////////////////////////////////////////////////////////////////////////
15 {
16 const Record_Id max_record_id
17 (
18 arguments.get_option<index_t>("max_record_id", "n", -1)
19 );
20
21 arguments.add_parameter("<file>");
22
23 const bool default_only = false;
24 const bool include_shared = false;
25
26 File_Parser file_parser
27 (
29 default_only,
30 include_shared
31 );
32
33 std::ostream null_stream(nullptr);
34 Buffered_File *file = file_parser.parse(null_stream, arguments);
35
36 if (!file)
37 {
38 arguments.print_help(std::cerr) << '\n';
39 file_parser.print_help(std::cerr);
40 return 1;
41 }
42
43 Blob_Reader_Command_Processor blob_processor(*file);
44
45 if (file->is_readonly())
46 {
47 Database db(max_record_id);
48 Readonly_Journal journal(*file);
49 journal.replay_log(db);
50 Readable_Interpreter interpreter(db);
51 interpreter.add_processor(blob_processor);
52 interpreter.main_loop(std::cin, std::cout);
53 }
54 else
55 {
56 Connection connection;
57
58 Writable_Database_Client client
59 (
60 *file,
61 connection,
63 max_record_id
64 );
65
66 client.transaction([max_record_id, &blob_processor]
67 (
68 const Readable &readable,
69 Writable &writable
70 )
71 {
72 Interpreter interpreter(readable, writable, max_record_id);
73 interpreter.add_processor(blob_processor);
74 interpreter.main_loop(std::cin, std::cout);
75 });
76 }
77
78 return 0;
79 }
80}
81
82/////////////////////////////////////////////////////////////////////////////
83int main(int argc, char **argv)
84/////////////////////////////////////////////////////////////////////////////
85{
86 return joedb::main_wrapper(joedb::joedbi, argc, argv);
87}
int main()
ptrdiff_t index_t
Definition index_types.h:18
@ write_existing_or_create_new
either write_existing or create_new depending on whether the file exists. Racy in Posix,...
int main_wrapper(int(*main)(Arguments &), int argc, char **argv)
Process command-line arguments and catch exceptions from main.
Definition Blob.h:7