diff options
author | neodarz <neodarz@neodarz.net> | 2019-08-08 13:48:39 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-08-08 13:48:39 +0200 |
commit | 4671f4a46bf9aca39f0a09d0bec115a7f8913614 (patch) | |
tree | 8ed81cc3fcd0a656340fdfe4ae422ce22c5738d2 /db/mongo_access.h | |
parent | 889093b2ea55969e8c2920652bdf36bfa3a04cc2 (diff) | |
download | umosapicpp-4671f4a46bf9aca39f0a09d0bec115a7f8913614.tar.xz umosapicpp-4671f4a46bf9aca39f0a09d0bec115a7f8913614.zip |
Implement mongocxx pool connection
Diffstat (limited to '')
-rw-r--r-- | db/mongo_access.h | 43 |
1 files changed, 43 insertions, 0 deletions
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 |