Joedb 10.2.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 Abstract_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 Writable_Database_Client client
57 (
58 *file,
61 max_record_id
62 );
63
64 client.transaction([max_record_id, &blob_processor]
65 (
66 const Readable &readable,
67 Writable &writable
68 )
69 {
70 Interpreter interpreter(readable, writable, max_record_id);
71 interpreter.add_processor(blob_processor);
72 interpreter.main_loop(std::cin, std::cout);
73 });
74 }
75
76 return 0;
77 }
78}
79
80/////////////////////////////////////////////////////////////////////////////
81int main(int argc, char **argv)
82/////////////////////////////////////////////////////////////////////////////
83{
84 return joedb::main_wrapper(joedb::joedbi, argc, argv);
85}
static Connection dummy
Since this class has no internal state, this global variable can be used instead of creating an insta...
Definition Connection.h:107
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.