/** * * @file DbClientManager.h * @author An Tao * * Copyright 2018, An Tao. All rights reserved. * https://github.com/an-tao/drogon * Use of this source code is governed by a MIT license * that can be found in the License file. * * Drogon * */ #pragma once #include #include #include #include #include #include #include #include namespace drogon { namespace orm { class DbClientManager : public trantor::NonCopyable { public: void createDbClients(const std::vector &ioLoops); DbClientPtr getDbClient(const std::string &name) { assert(dbClientsMap_.find(name) != dbClientsMap_.end()); return dbClientsMap_[name]; } ~DbClientManager(); DbClientPtr getFastDbClient(const std::string &name) { auto iter = dbFastClientsMap_.find(name); assert(iter != dbFastClientsMap_.end()); return iter->second.getThreadData(); } void addDbClient(const DbConfig &config); bool areAllDbClientsAvailable() const noexcept; private: std::map dbClientsMap_; struct DbInfo { std::string connectionInfo_; DbConfig config_; }; std::vector dbInfos_; std::map> dbFastClientsMap_; }; } // namespace orm } // namespace drogon