4#include "Stroika/Frameworks/StroikaPreComp.h"
9#include "Stroika/Foundation/Database/Document/MongoDBClient.h"
13#include "Stroika/Foundation/Execution/CommandLine.h"
14#include "Stroika/Foundation/Execution/Module.h"
18#include "ComputerNetwork.h"
19#include "EmployeesDB.h"
25using namespace Stroika::Foundation::Database;
28int main ([[maybe_unused]]
int argc, [[maybe_unused]]
const char* argv[])
30 using namespace Database::Document;
32 using namespace Stroika::Samples::Document;
34#if qStroika_HasComponent_mongocxxdriver
35 optional<String> mongoConnectionString;
40 using namespace StandardCommandLineOptions;
42 .fLongName =
"mongoConnectionString"sv,
43 .fSupportsArgument =
true,
44 .fHelpOptionText =
"Connect to this mongo database for testing, eg: mongodb://admin:pass@localhost:27017; OR ENV VAR MONGO_CONNECTION_STRING"sv};
46 const initializer_list<CommandLine::Option> kAllOptions_{kHelp,
47#if qStroika_HasComponent_mongocxxdriver
48 kMongoConnectionStringOption_
53 if (cmdLine.Has (kHelp)) {
54 cerr << CommandLine::GenerateUsage (
"documentDB", kAllOptions_);
57 if (
auto error = cmdLine.ValidateQuietly (kAllOptions_)) {
58 cerr <<
"{}"_f(*error) << endl;
59 cerr << CommandLine::GenerateUsage (
"myApp", kAllOptions_) << endl;
61#if qStroika_HasComponent_mongocxxdriver
62 mongoConnectionString = Memory::Or_Else (cmdLine.GetArgument (kMongoConnectionStringOption_),
63 [] () { return kEnvironment->Lookup (
"MONGO_CONNECTION_STRING"sv); });
67#if qStroika_HasComponent_mongocxxdriver
68 Database::Document::MongoDBClient::Activator activator{};
71#if qStroika_HasComponent_mongocxxdriver
72 if (not mongoConnectionString) {
73 cerr <<
"Warning: skipping mongodb test because no connection string specified on command-line nor environment variable" << endl;
75 if (mongoConnectionString) {
76 using namespace Stroika::Foundation::Database::Document::MongoDBClient;
77 const String kTestDBName_ =
"DocumentDB-Sample-Networks"sv;
79 static const Activity kMongoCXXActivity_{
"performing MongoDBClient test on {}"_f(kTestDBName_)};
81 auto adminDB = AdminConnection::New (AdminConnection::Options{.fConnectionTarget = *mongoConnectionString});
82 IgnoreExceptionsForCall (adminDB.DropDatabase (kTestDBName_));
83 adminDB.CreateDatabase (kTestDBName_);
85 MongoDBClient::Connection::Options{.fConnectionTarget = *mongoConnectionString, .fDatabase = kTestDBName_});
86 cerr <<
"Starting MongoDBClient networks sample:" << endl;
87 ComputerNetworksModel ([=] () {
88 cerr <<
"\tConnecting to {} database {}"_f(*mongoConnectionString, kTestDBName_) << endl;
89 return MongoDBClient::Connection::New (
90 MongoDBClient::Connection::Options{.fConnectionTarget = *mongoConnectionString, .fDatabase = kTestDBName_});
92 cerr <<
"done." << endl;
95 cerr <<
"\t{}"_f(current_exception ()) << endl;
98 if (mongoConnectionString) {
99 using namespace Stroika::Foundation::Database::Document::MongoDBClient;
100 const String kTestDBName_ =
"DocumentDB-Sample-Employees"sv;
102 static const Activity kMongoCXXActivity_{
"performing MongoDBClient test on {}"_f(kTestDBName_)};
104 auto adminDB = AdminConnection::New (AdminConnection::Options{.fConnectionTarget = *mongoConnectionString});
105 IgnoreExceptionsForCall (adminDB.DropDatabase (kTestDBName_));
106 adminDB.CreateDatabase (kTestDBName_);
108 MongoDBClient::Connection::Options{.fConnectionTarget = *mongoConnectionString, .fDatabase = kTestDBName_});
109 cerr <<
"Starting mongodb employees sample:" << endl;
110 EmployeesDB ([=] () {
111 cerr <<
"\tConnecting to {} database {}"_f(*mongoConnectionString, kTestDBName_) << endl;
112 return MongoDBClient::Connection::New (
113 MongoDBClient::Connection::Options{.fConnectionTarget = *mongoConnectionString, .fDatabase = kTestDBName_});
115 cerr <<
"done." << endl;
118 cerr <<
"\t{}"_f(current_exception ()) << endl;
123#if qStroika_HasComponent_sqlite
126 const String kTestDBName_ =
"DocumentDB-Sample-Networks"sv;
127 static const Activity kMongoCXXActivity_{
"performing sqlite document db networks sample on {}"_f(kTestDBName_)};
129 cerr <<
"Starting sqlite document db networks sample:" << endl;
130 ComputerNetworksModel ([=] () {
131 cerr <<
"\tConnecting to sqlite memory db: {}"_f(kTestDBName_) << endl;
132 return SQLite::Connection::New (SQLite::Connection::Options{.fInMemoryDB = kTestDBName_});
134 cerr <<
"done." << endl;
137 cerr <<
"\t{}"_f(current_exception ()) << endl;
140 const String kTestDBName_ =
"DocumentDB-Sample-Employees"sv;
141 static const Activity kMongoCXXActivity_{
"performing sqlite document db employees sample on {}"_f(kTestDBName_)};
143 cerr <<
"Starting sqlite document db employees sample on memory db {}"_f(kTestDBName_) << endl;
144 EmployeesDB ([=] () {
145 cerr <<
"\tConnecting to sqlite memory db: {}"_f(kTestDBName_) << endl;
146 return SQLite::Connection::New (SQLite::Connection::Options{.fInMemoryDB = kTestDBName_});
148 cerr <<
"done." << endl;
151 cerr <<
"\t{}"_f(current_exception ()) << endl;
156 static const Activity kMongoCXXActivity_{
"performing sqlite document db networks sample on {}"_f(dbPath)};
159 cerr <<
"Starting sqlite document db networks sample:" << endl;
160 ComputerNetworksModel ([=] () {
161 cerr <<
"\tConnecting to sqlite db: {}"_f(dbPath) << endl;
162 return SQLite::Connection::New (SQLite::Connection::Options{.fDBPath = dbPath});
164 cerr <<
"done." << endl;
167 cerr <<
"\t{}"_f(current_exception ()) << endl;
171 static const Activity kMongoCXXActivity_{
"performing Starting sqlite document db employees sample on {}"_f(dbPath)};
174 cerr <<
"Starting sqlite document db employees sample on {}"_f(dbPath) << endl;
175 EmployeesDB ([=] () {
176 cerr <<
"\tConnecting to sqlite db: {}"_f(dbPath) << endl;
177 auto c = SQLite::Connection::New (SQLite::Connection::Options{.fDBPath = dbPath});
180 cerr <<
"done." << endl;
183 cerr <<
"\t{}"_f(current_exception ()) << endl;
187 static const Activity kMongoCXXActivity_{
"performing trivial document db networks sample"sv};
189 cerr <<
"Starting trivial document db networks sample:" << endl;
190 auto internallySynchronizedDBConnection =
192 ComputerNetworksModel ([=] () {
193 cerr <<
"\tConnecting to trivial document db: memory" << endl;
194 return internallySynchronizedDBConnection;
196 cerr <<
"done." << endl;
199 cerr <<
"\t{}"_f(current_exception ()) << endl;
202 static const Activity kMongoCXXActivity_{
"performing trivial document db employees sample"sv};
204 cerr <<
"Starting trivial document db employees sample:" << endl;
205 auto internallySynchronizedDBConnection =
207 EmployeesDB ([=] () {
208 cerr <<
"\tConnecting to trivial document db: memory" << endl;
209 return internallySynchronizedDBConnection;
211 cerr <<
"done." << endl;
214 cerr <<
"\t{}"_f(current_exception ()) << endl;
String is like std::u32string, except it is much easier to use, often much more space efficient,...
filesystem::path GetTemporary()