Skip to content

Commit

Permalink
db: Construct underlying sql::Connection with sql::Properties and opt…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
zach2good committed Dec 20, 2024
1 parent 32ee8de commit 89b103b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/common/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,20 @@ mutex_guarded<db::detail::State>& db::detail::getState()
auto schema = settings::get<std::string>("network.SQL_DATABASE");
auto url = fmt::format("tcp://{}:{}", host, port);

state.connection = std::unique_ptr<sql::Connection>(driver->connect(url.c_str(), login.c_str(), passwd.c_str()));
sql::Properties properties;

// Connection information
properties["userName"] = login;
properties["password"] = passwd;

// Connection options
// https://github.com/mariadb-corporation/mariadb-connector-cpp/blob/master/README
properties["connectTimeout"] = "0";
properties["socketTimeout"] = "0";
properties["autoReconnect"] = "true";
properties["useCompression"] = "true";

state.connection = std::unique_ptr<sql::Connection>(driver->connect(url.c_str(), properties));
state.connection->setSchema(schema.c_str());
}
catch (const std::exception& e)
Expand Down

0 comments on commit 89b103b

Please sign in to comment.