Joedb 10.3.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedbi.cpp
Go to the documentation of this file.
8
9#include <iostream>
10
11namespace joedb
12{
13 ////////////////////////////////////////////////////////////////////////////
14 static int joedbi(Arguments &arguments)
15 ////////////////////////////////////////////////////////////////////////////
16 {
17 Parsed_Logger logger(arguments);
18
19 const Record_Id max_record_id
20 (
21 arguments.get_option<index_t>("max_record_id", "n", -1)
22 );
23
24 arguments.add_parameter("<file>");
25
26 const bool default_only = false;
27 const bool include_shared = false;
28
29 File_Parser file_parser
30 (
32 default_only,
33 include_shared
34 );
35
36 Abstract_File *file = file_parser.parse(logger.get(), arguments);
37
38 if (!file)
39 {
40 arguments.print_help(std::cerr) << '\n';
41 file_parser.print_help(std::cerr);
42 return 1;
43 }
44
45 Blob_Reader_Command_Processor blob_processor(*file);
46
47 if (file->is_readonly())
48 {
49 Database db(max_record_id);
50 Readonly_Journal journal(*file);
51 journal.replay_log(db);
52 Readable_Interpreter interpreter(db);
53 interpreter.add_processor(blob_processor);
54 interpreter.main_loop(std::cin, std::cout);
55 }
56 else
57 {
58 Writable_Database_Client client
59 (
60 *file,
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}
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.