|
nanoMMO 0.97.8
Building an MMO: The Engineering Series
|
#include <database.h>
Public Member Functions | |
| ~Database () | |
| Database (const Database &)=delete | |
| Database & | operator= (const Database &)=delete |
| absl::StatusOr< Result > | Run (std::string_view sql, const std::vector< std::string > &values={}) |
| absl::Status | Transaction (const std::function< absl::Status()> &statements) |
Static Public Member Functions | |
| static absl::StatusOr< std::unique_ptr< Database > > | Create (const std::string &host, const std::string &user, const std::string &password, const std::string &name, MysqlTimeouts timeouts={}) |
Static Public Attributes | |
| static constexpr std::size_t | kMostReads = 64 |
| The most reads a connection keeps prepared. | |
Definition at line 50 of file database.h.
| nanommo::Database::~Database | ( | ) |
Definition at line 162 of file database.cc.
|
delete |
|
static |
Connects to MySQL, at the host, which can name a port as host:port, or returns why it couldn't.
Definition at line 106 of file database.cc.
| absl::StatusOr< Result > nanommo::Database::Run | ( | std::string_view | sql, |
| const std::vector< std::string > & | values = {} ) |
Values go apart from the SQL, one for each ?, so they stay values. A duplicate key comes back as an AlreadyExists error, a lost connection as Unavailable, and a lock waited for too long, or a deadlock, as Aborted. A SELECT is prepared the first time it runs, and kept, so that it runs in one round trip after that, not two. A statement MySQL doesn't answer in time fails as Unavailable, and so does each after it, at once, until the timeouts' fail_fast is over.
Definition at line 186 of file database.cc.
| absl::Status nanommo::Database::Transaction | ( | const std::function< absl::Status()> & | statements | ) |
Runs the statements as one transaction, so that either all of them happen, or none does: none if one of them fails, or if the connection goes. A lost connection isn't tried again inside a transaction, as what ran before it on that connection is gone.
Definition at line 299 of file database.cc.
|
staticconstexpr |
The most reads a connection keeps prepared.
Definition at line 64 of file database.h.