Class Database

Class Documentation

class Database

Public Functions

inline Database()
Database(std::vector<std::string> info)
Database(std::string host, int port, std::string user, std::string pass, std::string schema = "", std::string table = "")
~Database()
void initialize_class()
void initialize_class(std::vector<std::string> dbinfo)
mysqlx::RowResult read(const std::vector<std::string> &columns, const std::string &where_clause, const std::map<std::string, mysqlx::Value> &bind_params, const std::string &order_by = "", std::optional<int> limit = std::nullopt, std::optional<int> offset = std::nullopt)
mysqlx::RowResult read(const std::string &tablename, const std::vector<std::string> &columns, const std::string &where_clause, const std::map<std::string, mysqlx::Value> &bind_params, const std::string &order_by = "", std::optional<int> limit = std::nullopt, std::optional<int> offset = std::nullopt)
mysqlx::RowResult read(const std::string &schemaname, const std::string &tablename, const std::vector<std::string> &columns, const std::string &where_clause, const std::map<std::string, mysqlx::Value> &bind_params = {}, const std::string &order_by = "", std::optional<int> limit = std::nullopt, std::optional<int> offset = std::nullopt)
void insert()
void insert(const std::map<std::string, mysqlx::Value> &data)
void insert(const std::string &tablename, const std::map<std::string, mysqlx::Value> &data)
void insert(const std::string &schemaname, const std::string &tablename, const std::map<std::string, mysqlx::Value> &data)
void update(const std::map<std::string, mysqlx::Value> &data, const std::string &condition, const std::map<std::string, mysqlx::Value> &bindings)
void update(const std::string &schemaname, const std::string &tablename, const std::map<std::string, mysqlx::Value> &data, const std::string &condition, const std::map<std::string, mysqlx::Value> &bindings)
std::list<std::string> get_tablenames()
std::list<std::string> get_tablenames(const std::string &schemaname)
template<typename T>
inline void add_key_val(const std::string &key, T value)

adds a key,value pair to the Database class

This adds a row into memory that will make up the complete record to be written. The private _data map contains data as mysqlx::Value indexed by name. msqlx::Value is essentially a variant so it can hold a mix of any different type.

Parameters:
  • key[in] name for the database column, or field

  • value[in] value of entry can be any type

template<typename T>
inline void add_from_json(const nlohmann::json &jmessage, const std::string &jkey, const std::string &optional = "")

verifies key in json message and adds key/val to Database::_data

Accepts a json message and key, verifies the key is in the message and the value is not null, and if that passes then use the add_key_val() function to add the associated value to the Database class internal _data map.

Parameters:
  • jmessage[in] json message

  • jkey[in] key to extract value from json message

  • optional[in] optional database key, defaults to json key

template<typename T>
inline void insert(std::map<std::string, T> data)

insert an STL map of any single type rather than mysqlx::Value

Parameters:

data[in] map of data of any single type, indexed by field name