nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
nanommo::Database Class Reference

#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.

Detailed Description

Definition at line 50 of file database.h.

Constructor & Destructor Documentation

◆ ~Database()

nanommo::Database::~Database ( )

Definition at line 162 of file database.cc.

◆ Database()

nanommo::Database::Database ( const Database & )
delete

Member Function Documentation

◆ Create()

absl::StatusOr< std::unique_ptr< Database > > nanommo::Database::Create ( const std::string & host,
const std::string & user,
const std::string & password,
const std::string & name,
MysqlTimeouts timeouts = {} )
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.

◆ operator=()

Database & nanommo::Database::operator= ( const Database & )
delete

◆ Run()

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.

◆ Transaction()

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.

Member Data Documentation

◆ kMostReads

std::size_t nanommo::Database::kMostReads = 64
staticconstexpr

The most reads a connection keeps prepared.

Definition at line 64 of file database.h.


The documentation for this class was generated from the following files: