aboutsummaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--db/mongo_access.cpp16
-rw-r--r--db/mongo_access.h43
2 files changed, 59 insertions, 0 deletions
diff --git a/db/mongo_access.cpp b/db/mongo_access.cpp
new file mode 100644
index 0000000..56936f3
--- /dev/null
+++ b/db/mongo_access.cpp
@@ -0,0 +1,16 @@
+#include "mongo_access.h"
+
+mongo_access::mongo_access(void) {};
+mongo_access::~mongo_access(void) {};
+
+void mongo_access::configure(mongocxx::uri uri) {
+ class noop_logger : public mongocxx::logger {
+ public:
+ virtual void operator()(mongocxx::log_level,
+ bsoncxx::stdx::string_view,
+ bsoncxx::stdx::string_view) noexcept {}
+ };
+
+ _pool = bsoncxx::stdx::make_unique<mongocxx::pool>(std::move(uri));
+ _instance = bsoncxx::stdx::make_unique<mongocxx::instance>(bsoncxx::stdx::make_unique<noop_logger>());
+}
diff --git a/db/mongo_access.h b/db/mongo_access.h
new file mode 100644
index 0000000..f03cece
--- /dev/null
+++ b/db/mongo_access.h
@@ -0,0 +1,43 @@
+#ifndef MongoAccess_H_
+#define MongoAccess_H_
+
+#include <cstdlib>
+#include <memory>
+
+#include <bsoncxx/stdx/make_unique.hpp>
+#include <bsoncxx/stdx/optional.hpp>
+#include <bsoncxx/stdx/string_view.hpp>
+
+#include <mongocxx/instance.hpp>
+#include <mongocxx/logger.hpp>
+#include <mongocxx/pool.hpp>
+#include <mongocxx/uri.hpp>
+
+#include <iostream>
+
+
+class mongo_access {
+ public:
+
+ mongo_access ();
+ ~mongo_access ();
+
+ void configure(mongocxx::uri uri);
+
+ using connection = mongocxx::pool::entry;
+
+ connection get_connection() {
+ return _pool->acquire();
+ }
+
+ bsoncxx::stdx::optional<connection> try_get_connection() {
+ return _pool->try_acquire();
+ }
+
+ private:
+ std::unique_ptr<mongocxx::instance> _instance = nullptr;
+ std::unique_ptr<mongocxx::pool> _pool = nullptr;
+
+};
+
+#endif