diff --git a/Doxyfile b/Doxyfile index b085ff1..838f202 100644 --- a/Doxyfile +++ b/Doxyfile @@ -749,7 +749,7 @@ WARN_LOGFILE = # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = database.h config.h +INPUT = database.h config.h README.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/docs/annotated.html b/docs/annotated.html index db4b8d8..57d004d 100644 --- a/docs/annotated.html +++ b/docs/annotated.html @@ -97,7 +97,7 @@ diff --git a/docs/classes.html b/docs/classes.html index 1001633..53fa8e0 100644 --- a/docs/classes.html +++ b/docs/classes.html @@ -97,7 +97,7 @@ diff --git a/docs/deprecated.html b/docs/deprecated.html index 10f72f8..aebabee 100644 --- a/docs/deprecated.html +++ b/docs/deprecated.html @@ -98,7 +98,7 @@ diff --git a/docs/functions.html b/docs/functions.html index 4e78f85..f30ec73 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -125,7 +125,7 @@ diff --git a/docs/functions_func.html b/docs/functions_func.html index 36ac181..972f626 100644 --- a/docs/functions_func.html +++ b/docs/functions_func.html @@ -116,7 +116,7 @@ diff --git a/docs/functions_vars.html b/docs/functions_vars.html index 51a18f9..909872e 100644 --- a/docs/functions_vars.html +++ b/docs/functions_vars.html @@ -98,7 +98,7 @@ diff --git a/docs/graph_legend.html b/docs/graph_legend.html index 2e75e81..1c00ef6 100644 --- a/docs/graph_legend.html +++ b/docs/graph_legend.html @@ -151,7 +151,7 @@ diff --git a/docs/index.html b/docs/index.html index 759caac..50fcd9d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ -DPP-MySQL: Main Page +DPP-MySQL: A simple asynchronous MySQL wrapper for D++ bots @@ -81,17 +81,110 @@ -
+
-
DPP-MySQL Documentation
+
A simple asynchronous MySQL wrapper for D++ bots
+

Simply take the source files and add them to your D++ bot project. This is a slightly modified version of what is used in my own bots.

+

This wrapper supports both synchronous (blocking) API and asynchronous (coroutine) API, alongside callback based async. All queries done through this wrapper use cached prepared statements, this will consume a very small amount of ram for a sometimes drastic increase in performance.

+

It is thread safe, however be aware that different threads may run queries that may intrude into other threads transactions. If you need ACID transaction safety, you should only use db::co_transaction() or db::transaction() and ensure all queries within use db::query().

+

No support is offered for this software at present. Your mileage may vary. I have only ever used this wrapper on Linux.

+

Detecting and linking the dependencies (libmysqlclient.so etc) is currently your responsibility. No package mangagement or build script is provided.

+

+Documentation

+

Doxygen documentation can be found on github pages. It can be re-generated by running 'doxygen'

+

+Dependencies

+
    +
  • libmysqlclient-dev
  • +
  • D++
  • +
  • fmtlib
  • +
  • A C++ compiler capable of building D++ bots with coroutine support, if you want to use the asynchronous interface
  • +
+

+Documentation

+

All functions in the db namespace have Doxygen comment blocks.

+

+Using the wrapper

+

+Simple Queries

+

This is an example of using the asynchronous interface:

+
#include <dpp/dpp.h>
+
#include "database.h"
+
#include "config.h"
+
+
int main(int argc, char const *argv[]) {
+
config::init("config.json");
+
dpp::cluster bot(config::get("token"));
+
+
bot.on_ready([&bot](const dpp::ready_t& event) -> dpp::task<void> {
+
+
auto rs = co_await db::co_query("SELECT * FROM bigtable WHERE bar = ?", { "baz" });
+
if (!rs.ok()) {
+
std::cout << "SQL error: " << rs.error << "\n";
+
co_return;
+
}
+
+
std::cout << "Number of rows returned: " << rs.size() << "\n";
+
if (!rs.empty()) {
+
std::cout << "First row 'bar' value: " << rs[0].at("bar") << "\n";
+
}
+
+
co_return;
+
});
+
+
db::init(bot);
+
bot.start(dpp::st_wait);
+
}
+
void init(const std::string &config_file)
Initialise config file.
+
json & get(const std::string &key="")
Get all config values from a specific key.
+
void init(dpp::cluster &bot)
Initialise database connection.
+
dpp::async< resultset > co_query(const std::string &format, const paramlist &parameters={})
Run a mysql query, with automatic escaping of parameters to prevent SQL injection....
+

Also create a config.json file. To use unix sockets to connect, set the port value to 0 and the hostname value to localhost.

+
{
+
"token": "discord bot token",
+
"database": {
+
"host": "hostname",
+
"username": "database username",
+
"password": "database password",
+
"database": "schema name",
+
"port": 0,
+
"socket": "/path/to/mysqld.sock"
+
}
+
}
+

+Using Transactions

+

To use transactions, wrap the transaction in the db::transaction function, and use only the db::query function within it for queries. Return true to commit the transaction, or throw any exception or return false to roll back the transaction.

+

Note that during a transaction all other queries will be forced to wait until the transaction is completed. Transactions are asynchronous, so use the callback to be notified when it completes, or use co_transaction as below:

+
#include <dpp/dpp.h>
+
#include "database.h"
+
#include "config.h"
+
+
int main(int argc, char const *argv[]) {
+
config::init("config.json");
+
dpp::cluster bot(config::get("token"));
+
+
bot.on_ready([&bot](const dpp::ready_t& event) -> dpp::task<void> {
+
co_await db::co_transaction([event]() -> bool {
+
auto rs = db::query("SELECT current FROM data");
+
db::query("UPDATE data SET previous = ?", { rs[0].at("data") });
+
return true;
+
});
+
});
+
+
db::init(bot);
+
bot.start(dpp::st_wait);
+
}
+
dpp::async< resultset > co_transaction(std::function< bool()> closure)
Start an SQL transaction in a coroutine that can be awaited. SQL transactions are atomic in nature,...
+
resultset query(const std::string &format, const paramlist &parameters={})
Run a mysql query, with automatic escaping of parameters to prevent SQL injection.
+
diff --git a/docs/namespaceconfig.html b/docs/namespaceconfig.html index 4167fd6..92209d3 100644 --- a/docs/namespaceconfig.html +++ b/docs/namespaceconfig.html @@ -185,7 +185,7 @@

diff --git a/docs/namespacedb.html b/docs/namespacedb.html index c1e3fc6..b5c61af 100644 --- a/docs/namespacedb.html +++ b/docs/namespacedb.html @@ -674,7 +674,7 @@

    - +
diff --git a/docs/namespacemembers.html b/docs/namespacemembers.html index 6b27fca..9377f04 100644 --- a/docs/namespacemembers.html +++ b/docs/namespacemembers.html @@ -144,7 +144,7 @@ diff --git a/docs/namespacemembers_func.html b/docs/namespacemembers_func.html index 62e9cea..b6e5cd0 100644 --- a/docs/namespacemembers_func.html +++ b/docs/namespacemembers_func.html @@ -132,7 +132,7 @@ diff --git a/docs/namespacemembers_type.html b/docs/namespacemembers_type.html index 779fd5c..3a57f08 100644 --- a/docs/namespacemembers_type.html +++ b/docs/namespacemembers_type.html @@ -101,7 +101,7 @@ diff --git a/docs/namespaces.html b/docs/namespaces.html index c507345..c6656d8 100644 --- a/docs/namespaces.html +++ b/docs/namespaces.html @@ -98,7 +98,7 @@ diff --git a/docs/navtreedata.js b/docs/navtreedata.js index 20f7c18..d76740f 100644 --- a/docs/navtreedata.js +++ b/docs/navtreedata.js @@ -25,6 +25,15 @@ var NAVTREE = [ [ "DPP-MySQL", "index.html", [ + [ "A simple asynchronous MySQL wrapper for D++ bots", "index.html", [ + [ "Documentation", "index.html#autotoc_md1", null ], + [ "Dependencies", "index.html#autotoc_md2", null ], + [ "Documentation", "index.html#autotoc_md3", null ], + [ "Using the wrapper", "index.html#autotoc_md4", [ + [ "Simple Queries", "index.html#autotoc_md5", null ], + [ "Using Transactions", "index.html#autotoc_md6", null ] + ] ] + ] ], [ "Deprecated List", "deprecated.html", null ], [ "Namespaces", "namespaces.html", [ [ "Namespace List", "namespaces.html", "namespaces_dup" ], diff --git a/docs/navtreeindex0.js b/docs/navtreeindex0.js index cfa38e9..19957c4 100644 --- a/docs/navtreeindex0.js +++ b/docs/navtreeindex0.js @@ -1,50 +1,57 @@ var NAVTREEINDEX0 = { -"annotated.html":[2,0], -"classes.html":[2,1], -"deprecated.html":[0], -"functions.html":[2,2,0], -"functions_func.html":[2,2,1], -"functions_vars.html":[2,2,2], +"annotated.html":[3,0], +"classes.html":[3,1], +"deprecated.html":[1], +"functions.html":[3,2,0], +"functions_func.html":[3,2,1], +"functions_vars.html":[3,2,2], "index.html":[], -"namespaceconfig.html":[1,0,0], -"namespaceconfig.html#a3b6fc04da34bbdb59ec978612c865538":[1,0,0,2], -"namespaceconfig.html#a7948a6875d305616d8cebf8aaeeb6ae2":[1,0,0,0], -"namespaceconfig.html#abda9d2a5f8aaf27890a20b26c1cd2f10":[1,0,0,1], -"namespacedb.html":[1,0,1], -"namespacedb.html#a04e8c4c6ec113d7a0c0fc8e09cb2736e":[1,0,1,4], -"namespacedb.html#a20e993a57250f29c283e2215218c08ad":[1,0,1,5], -"namespacedb.html#a211fc5ec27542766439426c02a051cc0":[1,0,1,16], -"namespacedb.html#a2b4f92b15fde6491a19818b96b0d79d9":[1,0,1,17], -"namespacedb.html#a4d0c7c86dc46a5ce6d6200248df5f9f0":[1,0,1,7], -"namespacedb.html#a5ab43b4eb6eb0a777ab4eaebec076f5f":[1,0,1,1], -"namespacedb.html#a7cba5870abb1d49fe0f9fe17dd8ef15f":[1,0,1,9], -"namespacedb.html#a80cf41cd981806e9f418472a6d5e640b":[1,0,1,13], -"namespacedb.html#a8a004a2115b829e9f7258f4f65fcbe0b":[1,0,1,12], -"namespacedb.html#a8e64d322c430542846327f26e9d00ff6":[1,0,1,14], -"namespacedb.html#a9a28ec123a44c5f84d5957eb9f5ce96c":[1,0,1,3], -"namespacedb.html#aa2f6e9e0eb590eaf8ae67fba44cf6689":[1,0,1,10], -"namespacedb.html#ad9b1577c4b3310854fcfbbbd92e70c0b":[1,0,1,11], -"namespacedb.html#adda338dba46c43746e4a2e335e23123c":[1,0,1,6], -"namespacedb.html#aeb0f9df97c2f20440869770847ecde04":[1,0,1,15], -"namespacedb.html#af7195db6c7dd62386e36f3d9ea0c24f8":[1,0,1,2], -"namespacedb.html#af873c3dbbe3724ee0e31953ade03f2bd":[1,0,1,8], -"namespacemembers.html":[1,1,0], -"namespacemembers_func.html":[1,1,1], -"namespacemembers_type.html":[1,1,2], -"namespaces.html":[1,0], +"index.html":[0], +"index.html#autotoc_md1":[0,0], +"index.html#autotoc_md2":[0,1], +"index.html#autotoc_md3":[0,2], +"index.html#autotoc_md4":[0,3], +"index.html#autotoc_md5":[0,3,0], +"index.html#autotoc_md6":[0,3,1], +"namespaceconfig.html":[2,0,0], +"namespaceconfig.html#a3b6fc04da34bbdb59ec978612c865538":[2,0,0,2], +"namespaceconfig.html#a7948a6875d305616d8cebf8aaeeb6ae2":[2,0,0,0], +"namespaceconfig.html#abda9d2a5f8aaf27890a20b26c1cd2f10":[2,0,0,1], +"namespacedb.html":[2,0,1], +"namespacedb.html#a04e8c4c6ec113d7a0c0fc8e09cb2736e":[2,0,1,4], +"namespacedb.html#a20e993a57250f29c283e2215218c08ad":[2,0,1,5], +"namespacedb.html#a211fc5ec27542766439426c02a051cc0":[2,0,1,16], +"namespacedb.html#a2b4f92b15fde6491a19818b96b0d79d9":[2,0,1,17], +"namespacedb.html#a4d0c7c86dc46a5ce6d6200248df5f9f0":[2,0,1,7], +"namespacedb.html#a5ab43b4eb6eb0a777ab4eaebec076f5f":[2,0,1,1], +"namespacedb.html#a7cba5870abb1d49fe0f9fe17dd8ef15f":[2,0,1,9], +"namespacedb.html#a80cf41cd981806e9f418472a6d5e640b":[2,0,1,13], +"namespacedb.html#a8a004a2115b829e9f7258f4f65fcbe0b":[2,0,1,12], +"namespacedb.html#a8e64d322c430542846327f26e9d00ff6":[2,0,1,14], +"namespacedb.html#a9a28ec123a44c5f84d5957eb9f5ce96c":[2,0,1,3], +"namespacedb.html#aa2f6e9e0eb590eaf8ae67fba44cf6689":[2,0,1,10], +"namespacedb.html#ad9b1577c4b3310854fcfbbbd92e70c0b":[2,0,1,11], +"namespacedb.html#adda338dba46c43746e4a2e335e23123c":[2,0,1,6], +"namespacedb.html#aeb0f9df97c2f20440869770847ecde04":[2,0,1,15], +"namespacedb.html#af7195db6c7dd62386e36f3d9ea0c24f8":[2,0,1,2], +"namespacedb.html#af873c3dbbe3724ee0e31953ade03f2bd":[2,0,1,8], +"namespacemembers.html":[2,1,0], +"namespacemembers_func.html":[2,1,1], +"namespacemembers_type.html":[2,1,2], +"namespaces.html":[2,0], "pages.html":[], -"structdb_1_1resultset.html":[2,0,0,0], -"structdb_1_1resultset.html#a028a9421200bdbf595e7d403f216988a":[2,0,0,0,7], -"structdb_1_1resultset.html#a059b07133dfb34008790a954666d3d35":[2,0,0,0,8], -"structdb_1_1resultset.html#a2fdff6a05bd78d7128aebc04fe73dab0":[2,0,0,0,5], -"structdb_1_1resultset.html#a389e90d46194b5d1bc34ea7f878f75cc":[2,0,0,0,9], -"structdb_1_1resultset.html#a4d375d8a0ae6689604445ba3a8cc50b0":[2,0,0,0,1], -"structdb_1_1resultset.html#a50bb1893834affc727cfef157b45c629":[2,0,0,0,0], -"structdb_1_1resultset.html#a86664b2b52696b3732e21453851dae5b":[2,0,0,0,11], -"structdb_1_1resultset.html#a8a006c3139a16c2e3b07d68dfe85fb87":[2,0,0,0,6], -"structdb_1_1resultset.html#ad28608b9530c9de5cb0b9f1b87a7e785":[2,0,0,0,10], -"structdb_1_1resultset.html#af55948e04805ad63260dda313ffa6a17":[2,0,0,0,2], -"structdb_1_1resultset.html#af93c2af8068d3e2476184a43913d495f":[2,0,0,0,4], -"structdb_1_1resultset.html#aff83375461c2464d3b1f112e45732e09":[2,0,0,0,3] +"structdb_1_1resultset.html":[3,0,0,0], +"structdb_1_1resultset.html#a028a9421200bdbf595e7d403f216988a":[3,0,0,0,7], +"structdb_1_1resultset.html#a059b07133dfb34008790a954666d3d35":[3,0,0,0,8], +"structdb_1_1resultset.html#a2fdff6a05bd78d7128aebc04fe73dab0":[3,0,0,0,5], +"structdb_1_1resultset.html#a389e90d46194b5d1bc34ea7f878f75cc":[3,0,0,0,9], +"structdb_1_1resultset.html#a4d375d8a0ae6689604445ba3a8cc50b0":[3,0,0,0,1], +"structdb_1_1resultset.html#a50bb1893834affc727cfef157b45c629":[3,0,0,0,0], +"structdb_1_1resultset.html#a86664b2b52696b3732e21453851dae5b":[3,0,0,0,11], +"structdb_1_1resultset.html#a8a006c3139a16c2e3b07d68dfe85fb87":[3,0,0,0,6], +"structdb_1_1resultset.html#ad28608b9530c9de5cb0b9f1b87a7e785":[3,0,0,0,10], +"structdb_1_1resultset.html#af55948e04805ad63260dda313ffa6a17":[3,0,0,0,2], +"structdb_1_1resultset.html#af93c2af8068d3e2476184a43913d495f":[3,0,0,0,4], +"structdb_1_1resultset.html#aff83375461c2464d3b1f112e45732e09":[3,0,0,0,3] }; diff --git a/docs/pages.html b/docs/pages.html index 7d564e7..dd9c8c1 100644 --- a/docs/pages.html +++ b/docs/pages.html @@ -96,7 +96,7 @@ diff --git a/docs/search/all_0.js b/docs/search/all_0.js index 6329664..b365ab4 100644 --- a/docs/search/all_0.js +++ b/docs/search/all_0.js @@ -1,5 +1,6 @@ var searchData= [ - ['affected_5frows_0',['affected_rows',['../structdb_1_1resultset.html#a389e90d46194b5d1bc34ea7f878f75cc',1,'db::resultset::affected_rows()'],['../namespacedb.html#a20e993a57250f29c283e2215218c08ad',1,'db::affected_rows()']]], - ['at_1',['at',['../structdb_1_1resultset.html#a50bb1893834affc727cfef157b45c629',1,'db::resultset']]] + ['a_20simple_20asynchronous_20mysql_20wrapper_20for_20d_2b_2b_20bots_0',['A simple asynchronous MySQL wrapper for D++ bots',['../index.html',1,'']]], + ['affected_5frows_1',['affected_rows',['../structdb_1_1resultset.html#a389e90d46194b5d1bc34ea7f878f75cc',1,'db::resultset::affected_rows()'],['../namespacedb.html#a20e993a57250f29c283e2215218c08ad',1,'db::affected_rows()']]], + ['at_2',['at',['../structdb_1_1resultset.html#a50bb1893834affc727cfef157b45c629',1,'db::resultset']]] ]; diff --git a/docs/search/all_1.js b/docs/search/all_1.js index 5aa6935..7aa06ef 100644 --- a/docs/search/all_1.js +++ b/docs/search/all_1.js @@ -1,4 +1,4 @@ var searchData= [ - ['begin_2',['begin',['../structdb_1_1resultset.html#a4d375d8a0ae6689604445ba3a8cc50b0',1,'db::resultset']]] + ['begin_3',['begin',['../structdb_1_1resultset.html#a4d375d8a0ae6689604445ba3a8cc50b0',1,'db::resultset']]] ]; diff --git a/docs/search/all_2.js b/docs/search/all_2.js index e65787b..0ce3f6a 100644 --- a/docs/search/all_2.js +++ b/docs/search/all_2.js @@ -1,9 +1,9 @@ var searchData= [ - ['cache_5fsize_3',['cache_size',['../namespacedb.html#adda338dba46c43746e4a2e335e23123c',1,'db']]], - ['close_4',['close',['../namespacedb.html#a4d0c7c86dc46a5ce6d6200248df5f9f0',1,'db']]], - ['co_5fquery_5',['co_query',['../namespacedb.html#af873c3dbbe3724ee0e31953ade03f2bd',1,'db']]], - ['co_5ftransaction_6',['co_transaction',['../namespacedb.html#a7cba5870abb1d49fe0f9fe17dd8ef15f',1,'db']]], - ['config_7',['config',['../namespaceconfig.html',1,'']]], - ['connect_8',['connect',['../namespacedb.html#aa2f6e9e0eb590eaf8ae67fba44cf6689',1,'db']]] + ['cache_5fsize_4',['cache_size',['../namespacedb.html#adda338dba46c43746e4a2e335e23123c',1,'db']]], + ['close_5',['close',['../namespacedb.html#a4d0c7c86dc46a5ce6d6200248df5f9f0',1,'db']]], + ['co_5fquery_6',['co_query',['../namespacedb.html#af873c3dbbe3724ee0e31953ade03f2bd',1,'db']]], + ['co_5ftransaction_7',['co_transaction',['../namespacedb.html#a7cba5870abb1d49fe0f9fe17dd8ef15f',1,'db']]], + ['config_8',['config',['../namespaceconfig.html',1,'']]], + ['connect_9',['connect',['../namespacedb.html#aa2f6e9e0eb590eaf8ae67fba44cf6689',1,'db']]] ]; diff --git a/docs/search/all_3.js b/docs/search/all_3.js index 299969e..e9233f5 100644 --- a/docs/search/all_3.js +++ b/docs/search/all_3.js @@ -1,5 +1,5 @@ var searchData= [ - ['db_9',['db',['../namespacedb.html',1,'']]], - ['deprecated_20list_10',['Deprecated List',['../deprecated.html',1,'']]] + ['db_10',['db',['../namespacedb.html',1,'']]], + ['deprecated_20list_11',['Deprecated List',['../deprecated.html',1,'']]] ]; diff --git a/docs/search/all_4.js b/docs/search/all_4.js index a58028a..653a319 100644 --- a/docs/search/all_4.js +++ b/docs/search/all_4.js @@ -1,8 +1,8 @@ var searchData= [ - ['emplace_5fback_11',['emplace_back',['../structdb_1_1resultset.html#af55948e04805ad63260dda313ffa6a17',1,'db::resultset']]], - ['empty_12',['empty',['../structdb_1_1resultset.html#aff83375461c2464d3b1f112e45732e09',1,'db::resultset']]], - ['end_13',['end',['../structdb_1_1resultset.html#af93c2af8068d3e2476184a43913d495f',1,'db::resultset']]], - ['error_14',['error',['../structdb_1_1resultset.html#ad28608b9530c9de5cb0b9f1b87a7e785',1,'db::resultset::error()'],['../namespacedb.html#ad9b1577c4b3310854fcfbbbd92e70c0b',1,'db::error()']]], - ['exists_15',['exists',['../namespaceconfig.html#a7948a6875d305616d8cebf8aaeeb6ae2',1,'config']]] + ['emplace_5fback_12',['emplace_back',['../structdb_1_1resultset.html#af55948e04805ad63260dda313ffa6a17',1,'db::resultset']]], + ['empty_13',['empty',['../structdb_1_1resultset.html#aff83375461c2464d3b1f112e45732e09',1,'db::resultset']]], + ['end_14',['end',['../structdb_1_1resultset.html#af93c2af8068d3e2476184a43913d495f',1,'db::resultset']]], + ['error_15',['error',['../structdb_1_1resultset.html#ad28608b9530c9de5cb0b9f1b87a7e785',1,'db::resultset::error()'],['../namespacedb.html#ad9b1577c4b3310854fcfbbbd92e70c0b',1,'db::error()']]], + ['exists_16',['exists',['../namespaceconfig.html#a7948a6875d305616d8cebf8aaeeb6ae2',1,'config']]] ]; diff --git a/docs/search/all_5.js b/docs/search/all_5.js index 310365d..70d7da0 100644 --- a/docs/search/all_5.js +++ b/docs/search/all_5.js @@ -1,4 +1,4 @@ var searchData= [ - ['get_16',['get',['../namespaceconfig.html#abda9d2a5f8aaf27890a20b26c1cd2f10',1,'config']]] + ['get_17',['get',['../namespaceconfig.html#abda9d2a5f8aaf27890a20b26c1cd2f10',1,'config']]] ]; diff --git a/docs/search/all_6.js b/docs/search/all_6.js index 9469e66..0564206 100644 --- a/docs/search/all_6.js +++ b/docs/search/all_6.js @@ -1,4 +1,4 @@ var searchData= [ - ['init_17',['init',['../namespacedb.html#a8a004a2115b829e9f7258f4f65fcbe0b',1,'db::init()'],['../namespaceconfig.html#a3b6fc04da34bbdb59ec978612c865538',1,'config::init()']]] + ['init_18',['init',['../namespacedb.html#a8a004a2115b829e9f7258f4f65fcbe0b',1,'db::init()'],['../namespaceconfig.html#a3b6fc04da34bbdb59ec978612c865538',1,'config::init()']]] ]; diff --git a/docs/search/all_7.js b/docs/search/all_7.js index 43ecc24..109f2fc 100644 --- a/docs/search/all_7.js +++ b/docs/search/all_7.js @@ -1,5 +1,5 @@ var searchData= [ - ['ok_18',['ok',['../structdb_1_1resultset.html#a2fdff6a05bd78d7128aebc04fe73dab0',1,'db::resultset']]], - ['operator_5b_5d_19',['operator[]',['../structdb_1_1resultset.html#a8a006c3139a16c2e3b07d68dfe85fb87',1,'db::resultset']]] + ['ok_19',['ok',['../structdb_1_1resultset.html#a2fdff6a05bd78d7128aebc04fe73dab0',1,'db::resultset']]], + ['operator_5b_5d_20',['operator[]',['../structdb_1_1resultset.html#a8a006c3139a16c2e3b07d68dfe85fb87',1,'db::resultset']]] ]; diff --git a/docs/search/all_8.js b/docs/search/all_8.js index 9642cf3..bc6579b 100644 --- a/docs/search/all_8.js +++ b/docs/search/all_8.js @@ -1,6 +1,6 @@ var searchData= [ - ['parameter_5ftype_20',['parameter_type',['../namespacedb.html#a5ab43b4eb6eb0a777ab4eaebec076f5f',1,'db']]], - ['paramlist_21',['paramlist',['../namespacedb.html#af7195db6c7dd62386e36f3d9ea0c24f8',1,'db']]], - ['push_5fback_22',['push_back',['../structdb_1_1resultset.html#a028a9421200bdbf595e7d403f216988a',1,'db::resultset']]] + ['parameter_5ftype_21',['parameter_type',['../namespacedb.html#a5ab43b4eb6eb0a777ab4eaebec076f5f',1,'db']]], + ['paramlist_22',['paramlist',['../namespacedb.html#af7195db6c7dd62386e36f3d9ea0c24f8',1,'db']]], + ['push_5fback_23',['push_back',['../structdb_1_1resultset.html#a028a9421200bdbf595e7d403f216988a',1,'db::resultset']]] ]; diff --git a/docs/search/all_9.js b/docs/search/all_9.js index 611cce7..612585f 100644 --- a/docs/search/all_9.js +++ b/docs/search/all_9.js @@ -1,6 +1,6 @@ var searchData= [ - ['query_23',['query',['../namespacedb.html#a8e64d322c430542846327f26e9d00ff6',1,'db::query(const std::string &format, const paramlist &parameters={})'],['../namespacedb.html#a80cf41cd981806e9f418472a6d5e640b',1,'db::query(const std::string &format, const paramlist &parameters, double lifetime)']]], - ['query_5fcallback_24',['query_callback',['../namespacedb.html#aeb0f9df97c2f20440869770847ecde04',1,'db']]], - ['query_5fcount_25',['query_count',['../namespacedb.html#a211fc5ec27542766439426c02a051cc0',1,'db']]] + ['query_24',['query',['../namespacedb.html#a8e64d322c430542846327f26e9d00ff6',1,'db::query(const std::string &format, const paramlist &parameters={})'],['../namespacedb.html#a80cf41cd981806e9f418472a6d5e640b',1,'db::query(const std::string &format, const paramlist &parameters, double lifetime)']]], + ['query_5fcallback_25',['query_callback',['../namespacedb.html#aeb0f9df97c2f20440869770847ecde04',1,'db']]], + ['query_5fcount_26',['query_count',['../namespacedb.html#a211fc5ec27542766439426c02a051cc0',1,'db']]] ]; diff --git a/docs/search/all_a.js b/docs/search/all_a.js index c38d5b0..0d58acc 100644 --- a/docs/search/all_a.js +++ b/docs/search/all_a.js @@ -1,6 +1,6 @@ var searchData= [ - ['resultset_26',['resultset',['../structdb_1_1resultset.html',1,'db']]], - ['row_27',['row',['../namespacedb.html#a9a28ec123a44c5f84d5957eb9f5ce96c',1,'db']]], - ['rows_28',['rows',['../structdb_1_1resultset.html#a86664b2b52696b3732e21453851dae5b',1,'db::resultset']]] + ['resultset_27',['resultset',['../structdb_1_1resultset.html',1,'db']]], + ['row_28',['row',['../namespacedb.html#a9a28ec123a44c5f84d5957eb9f5ce96c',1,'db']]], + ['rows_29',['rows',['../structdb_1_1resultset.html#a86664b2b52696b3732e21453851dae5b',1,'db::resultset']]] ]; diff --git a/docs/search/all_b.js b/docs/search/all_b.js index 175a166..9e1c2e3 100644 --- a/docs/search/all_b.js +++ b/docs/search/all_b.js @@ -1,5 +1,5 @@ var searchData= [ - ['size_29',['size',['../structdb_1_1resultset.html#a059b07133dfb34008790a954666d3d35',1,'db::resultset']]], - ['sql_5fquery_5fcallback_30',['sql_query_callback',['../namespacedb.html#a04e8c4c6ec113d7a0c0fc8e09cb2736e',1,'db']]] + ['size_30',['size',['../structdb_1_1resultset.html#a059b07133dfb34008790a954666d3d35',1,'db::resultset']]], + ['sql_5fquery_5fcallback_31',['sql_query_callback',['../namespacedb.html#a04e8c4c6ec113d7a0c0fc8e09cb2736e',1,'db']]] ]; diff --git a/docs/search/all_c.js b/docs/search/all_c.js index fa65e2d..16e4ed4 100644 --- a/docs/search/all_c.js +++ b/docs/search/all_c.js @@ -1,4 +1,4 @@ var searchData= [ - ['transaction_31',['transaction',['../namespacedb.html#a2b4f92b15fde6491a19818b96b0d79d9',1,'db']]] + ['transaction_32',['transaction',['../namespacedb.html#a2b4f92b15fde6491a19818b96b0d79d9',1,'db']]] ]; diff --git a/docs/search/classes_0.js b/docs/search/classes_0.js index 19b18e0..fef4e4e 100644 --- a/docs/search/classes_0.js +++ b/docs/search/classes_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['resultset_32',['resultset',['../structdb_1_1resultset.html',1,'db']]] + ['resultset_33',['resultset',['../structdb_1_1resultset.html',1,'db']]] ]; diff --git a/docs/search/functions_0.js b/docs/search/functions_0.js index 12348de..05db6da 100644 --- a/docs/search/functions_0.js +++ b/docs/search/functions_0.js @@ -1,5 +1,5 @@ var searchData= [ - ['affected_5frows_35',['affected_rows',['../namespacedb.html#a20e993a57250f29c283e2215218c08ad',1,'db']]], - ['at_36',['at',['../structdb_1_1resultset.html#a50bb1893834affc727cfef157b45c629',1,'db::resultset']]] + ['affected_5frows_36',['affected_rows',['../namespacedb.html#a20e993a57250f29c283e2215218c08ad',1,'db']]], + ['at_37',['at',['../structdb_1_1resultset.html#a50bb1893834affc727cfef157b45c629',1,'db::resultset']]] ]; diff --git a/docs/search/functions_1.js b/docs/search/functions_1.js index c0d951c..092ba47 100644 --- a/docs/search/functions_1.js +++ b/docs/search/functions_1.js @@ -1,4 +1,4 @@ var searchData= [ - ['begin_37',['begin',['../structdb_1_1resultset.html#a4d375d8a0ae6689604445ba3a8cc50b0',1,'db::resultset']]] + ['begin_38',['begin',['../structdb_1_1resultset.html#a4d375d8a0ae6689604445ba3a8cc50b0',1,'db::resultset']]] ]; diff --git a/docs/search/functions_2.js b/docs/search/functions_2.js index 2c06cb8..895c7a8 100644 --- a/docs/search/functions_2.js +++ b/docs/search/functions_2.js @@ -1,8 +1,8 @@ var searchData= [ - ['cache_5fsize_38',['cache_size',['../namespacedb.html#adda338dba46c43746e4a2e335e23123c',1,'db']]], - ['close_39',['close',['../namespacedb.html#a4d0c7c86dc46a5ce6d6200248df5f9f0',1,'db']]], - ['co_5fquery_40',['co_query',['../namespacedb.html#af873c3dbbe3724ee0e31953ade03f2bd',1,'db']]], - ['co_5ftransaction_41',['co_transaction',['../namespacedb.html#a7cba5870abb1d49fe0f9fe17dd8ef15f',1,'db']]], - ['connect_42',['connect',['../namespacedb.html#aa2f6e9e0eb590eaf8ae67fba44cf6689',1,'db']]] + ['cache_5fsize_39',['cache_size',['../namespacedb.html#adda338dba46c43746e4a2e335e23123c',1,'db']]], + ['close_40',['close',['../namespacedb.html#a4d0c7c86dc46a5ce6d6200248df5f9f0',1,'db']]], + ['co_5fquery_41',['co_query',['../namespacedb.html#af873c3dbbe3724ee0e31953ade03f2bd',1,'db']]], + ['co_5ftransaction_42',['co_transaction',['../namespacedb.html#a7cba5870abb1d49fe0f9fe17dd8ef15f',1,'db']]], + ['connect_43',['connect',['../namespacedb.html#aa2f6e9e0eb590eaf8ae67fba44cf6689',1,'db']]] ]; diff --git a/docs/search/functions_3.js b/docs/search/functions_3.js index 010864a..07f5637 100644 --- a/docs/search/functions_3.js +++ b/docs/search/functions_3.js @@ -1,8 +1,8 @@ var searchData= [ - ['emplace_5fback_43',['emplace_back',['../structdb_1_1resultset.html#af55948e04805ad63260dda313ffa6a17',1,'db::resultset']]], - ['empty_44',['empty',['../structdb_1_1resultset.html#aff83375461c2464d3b1f112e45732e09',1,'db::resultset']]], - ['end_45',['end',['../structdb_1_1resultset.html#af93c2af8068d3e2476184a43913d495f',1,'db::resultset']]], - ['error_46',['error',['../namespacedb.html#ad9b1577c4b3310854fcfbbbd92e70c0b',1,'db']]], - ['exists_47',['exists',['../namespaceconfig.html#a7948a6875d305616d8cebf8aaeeb6ae2',1,'config']]] + ['emplace_5fback_44',['emplace_back',['../structdb_1_1resultset.html#af55948e04805ad63260dda313ffa6a17',1,'db::resultset']]], + ['empty_45',['empty',['../structdb_1_1resultset.html#aff83375461c2464d3b1f112e45732e09',1,'db::resultset']]], + ['end_46',['end',['../structdb_1_1resultset.html#af93c2af8068d3e2476184a43913d495f',1,'db::resultset']]], + ['error_47',['error',['../namespacedb.html#ad9b1577c4b3310854fcfbbbd92e70c0b',1,'db']]], + ['exists_48',['exists',['../namespaceconfig.html#a7948a6875d305616d8cebf8aaeeb6ae2',1,'config']]] ]; diff --git a/docs/search/functions_4.js b/docs/search/functions_4.js index 26abbda..7c37c9f 100644 --- a/docs/search/functions_4.js +++ b/docs/search/functions_4.js @@ -1,4 +1,4 @@ var searchData= [ - ['get_48',['get',['../namespaceconfig.html#abda9d2a5f8aaf27890a20b26c1cd2f10',1,'config']]] + ['get_49',['get',['../namespaceconfig.html#abda9d2a5f8aaf27890a20b26c1cd2f10',1,'config']]] ]; diff --git a/docs/search/functions_5.js b/docs/search/functions_5.js index 03f2abf..7b566f6 100644 --- a/docs/search/functions_5.js +++ b/docs/search/functions_5.js @@ -1,4 +1,4 @@ var searchData= [ - ['init_49',['init',['../namespacedb.html#a8a004a2115b829e9f7258f4f65fcbe0b',1,'db::init()'],['../namespaceconfig.html#a3b6fc04da34bbdb59ec978612c865538',1,'config::init()']]] + ['init_50',['init',['../namespacedb.html#a8a004a2115b829e9f7258f4f65fcbe0b',1,'db::init()'],['../namespaceconfig.html#a3b6fc04da34bbdb59ec978612c865538',1,'config::init()']]] ]; diff --git a/docs/search/functions_6.js b/docs/search/functions_6.js index 3504f39..f180638 100644 --- a/docs/search/functions_6.js +++ b/docs/search/functions_6.js @@ -1,5 +1,5 @@ var searchData= [ - ['ok_50',['ok',['../structdb_1_1resultset.html#a2fdff6a05bd78d7128aebc04fe73dab0',1,'db::resultset']]], - ['operator_5b_5d_51',['operator[]',['../structdb_1_1resultset.html#a8a006c3139a16c2e3b07d68dfe85fb87',1,'db::resultset']]] + ['ok_51',['ok',['../structdb_1_1resultset.html#a2fdff6a05bd78d7128aebc04fe73dab0',1,'db::resultset']]], + ['operator_5b_5d_52',['operator[]',['../structdb_1_1resultset.html#a8a006c3139a16c2e3b07d68dfe85fb87',1,'db::resultset']]] ]; diff --git a/docs/search/functions_7.js b/docs/search/functions_7.js index 9c5df29..3289f44 100644 --- a/docs/search/functions_7.js +++ b/docs/search/functions_7.js @@ -1,4 +1,4 @@ var searchData= [ - ['push_5fback_52',['push_back',['../structdb_1_1resultset.html#a028a9421200bdbf595e7d403f216988a',1,'db::resultset']]] + ['push_5fback_53',['push_back',['../structdb_1_1resultset.html#a028a9421200bdbf595e7d403f216988a',1,'db::resultset']]] ]; diff --git a/docs/search/functions_8.js b/docs/search/functions_8.js index 00f6de7..2773b50 100644 --- a/docs/search/functions_8.js +++ b/docs/search/functions_8.js @@ -1,6 +1,6 @@ var searchData= [ - ['query_53',['query',['../namespacedb.html#a8e64d322c430542846327f26e9d00ff6',1,'db::query(const std::string &format, const paramlist &parameters={})'],['../namespacedb.html#a80cf41cd981806e9f418472a6d5e640b',1,'db::query(const std::string &format, const paramlist &parameters, double lifetime)']]], - ['query_5fcallback_54',['query_callback',['../namespacedb.html#aeb0f9df97c2f20440869770847ecde04',1,'db']]], - ['query_5fcount_55',['query_count',['../namespacedb.html#a211fc5ec27542766439426c02a051cc0',1,'db']]] + ['query_54',['query',['../namespacedb.html#a8e64d322c430542846327f26e9d00ff6',1,'db::query(const std::string &format, const paramlist &parameters={})'],['../namespacedb.html#a80cf41cd981806e9f418472a6d5e640b',1,'db::query(const std::string &format, const paramlist &parameters, double lifetime)']]], + ['query_5fcallback_55',['query_callback',['../namespacedb.html#aeb0f9df97c2f20440869770847ecde04',1,'db']]], + ['query_5fcount_56',['query_count',['../namespacedb.html#a211fc5ec27542766439426c02a051cc0',1,'db']]] ]; diff --git a/docs/search/functions_9.js b/docs/search/functions_9.js index f632145..c63d7e6 100644 --- a/docs/search/functions_9.js +++ b/docs/search/functions_9.js @@ -1,4 +1,4 @@ var searchData= [ - ['size_56',['size',['../structdb_1_1resultset.html#a059b07133dfb34008790a954666d3d35',1,'db::resultset']]] + ['size_57',['size',['../structdb_1_1resultset.html#a059b07133dfb34008790a954666d3d35',1,'db::resultset']]] ]; diff --git a/docs/search/functions_a.js b/docs/search/functions_a.js index 07910b3..5da81eb 100644 --- a/docs/search/functions_a.js +++ b/docs/search/functions_a.js @@ -1,4 +1,4 @@ var searchData= [ - ['transaction_57',['transaction',['../namespacedb.html#a2b4f92b15fde6491a19818b96b0d79d9',1,'db']]] + ['transaction_58',['transaction',['../namespacedb.html#a2b4f92b15fde6491a19818b96b0d79d9',1,'db']]] ]; diff --git a/docs/search/namespaces_0.js b/docs/search/namespaces_0.js index b91c98e..18fc82b 100644 --- a/docs/search/namespaces_0.js +++ b/docs/search/namespaces_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['config_33',['config',['../namespaceconfig.html',1,'']]] + ['config_34',['config',['../namespaceconfig.html',1,'']]] ]; diff --git a/docs/search/namespaces_1.js b/docs/search/namespaces_1.js index e9db024..e21ca7f 100644 --- a/docs/search/namespaces_1.js +++ b/docs/search/namespaces_1.js @@ -1,4 +1,4 @@ var searchData= [ - ['db_34',['db',['../namespacedb.html',1,'']]] + ['db_35',['db',['../namespacedb.html',1,'']]] ]; diff --git a/docs/search/pages_0.js b/docs/search/pages_0.js index 4c113cd..d6b9485 100644 --- a/docs/search/pages_0.js +++ b/docs/search/pages_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['deprecated_20list_65',['Deprecated List',['../deprecated.html',1,'']]] + ['a_20simple_20asynchronous_20mysql_20wrapper_20for_20d_2b_2b_20bots_66',['A simple asynchronous MySQL wrapper for D++ bots',['../index.html',1,'']]] ]; diff --git a/docs/search/pages_1.html b/docs/search/pages_1.html new file mode 100644 index 0000000..a0fb679 --- /dev/null +++ b/docs/search/pages_1.html @@ -0,0 +1,37 @@ + + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/docs/search/pages_1.js b/docs/search/pages_1.js new file mode 100644 index 0000000..f71e488 --- /dev/null +++ b/docs/search/pages_1.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['deprecated_20list_67',['Deprecated List',['../deprecated.html',1,'']]] +]; diff --git a/docs/search/searchdata.js b/docs/search/searchdata.js index a40af14..c4037e0 100644 --- a/docs/search/searchdata.js +++ b/docs/search/searchdata.js @@ -6,7 +6,7 @@ var indexSectionsWithContent = 3: "abcegiopqst", 4: "aer", 5: "prs", - 6: "d" + 6: "ad" }; var indexSectionNames = diff --git a/docs/search/typedefs_0.js b/docs/search/typedefs_0.js index 695b7ef..7791e75 100644 --- a/docs/search/typedefs_0.js +++ b/docs/search/typedefs_0.js @@ -1,5 +1,5 @@ var searchData= [ - ['parameter_5ftype_61',['parameter_type',['../namespacedb.html#a5ab43b4eb6eb0a777ab4eaebec076f5f',1,'db']]], - ['paramlist_62',['paramlist',['../namespacedb.html#af7195db6c7dd62386e36f3d9ea0c24f8',1,'db']]] + ['parameter_5ftype_62',['parameter_type',['../namespacedb.html#a5ab43b4eb6eb0a777ab4eaebec076f5f',1,'db']]], + ['paramlist_63',['paramlist',['../namespacedb.html#af7195db6c7dd62386e36f3d9ea0c24f8',1,'db']]] ]; diff --git a/docs/search/typedefs_1.js b/docs/search/typedefs_1.js index cf36623..f1500c2 100644 --- a/docs/search/typedefs_1.js +++ b/docs/search/typedefs_1.js @@ -1,4 +1,4 @@ var searchData= [ - ['row_63',['row',['../namespacedb.html#a9a28ec123a44c5f84d5957eb9f5ce96c',1,'db']]] + ['row_64',['row',['../namespacedb.html#a9a28ec123a44c5f84d5957eb9f5ce96c',1,'db']]] ]; diff --git a/docs/search/typedefs_2.js b/docs/search/typedefs_2.js index e828969..0f157ec 100644 --- a/docs/search/typedefs_2.js +++ b/docs/search/typedefs_2.js @@ -1,4 +1,4 @@ var searchData= [ - ['sql_5fquery_5fcallback_64',['sql_query_callback',['../namespacedb.html#a04e8c4c6ec113d7a0c0fc8e09cb2736e',1,'db']]] + ['sql_5fquery_5fcallback_65',['sql_query_callback',['../namespacedb.html#a04e8c4c6ec113d7a0c0fc8e09cb2736e',1,'db']]] ]; diff --git a/docs/search/variables_0.js b/docs/search/variables_0.js index 15d9e89..c953757 100644 --- a/docs/search/variables_0.js +++ b/docs/search/variables_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['affected_5frows_58',['affected_rows',['../structdb_1_1resultset.html#a389e90d46194b5d1bc34ea7f878f75cc',1,'db::resultset']]] + ['affected_5frows_59',['affected_rows',['../structdb_1_1resultset.html#a389e90d46194b5d1bc34ea7f878f75cc',1,'db::resultset']]] ]; diff --git a/docs/search/variables_1.js b/docs/search/variables_1.js index 3202322..1b0dba2 100644 --- a/docs/search/variables_1.js +++ b/docs/search/variables_1.js @@ -1,4 +1,4 @@ var searchData= [ - ['error_59',['error',['../structdb_1_1resultset.html#ad28608b9530c9de5cb0b9f1b87a7e785',1,'db::resultset']]] + ['error_60',['error',['../structdb_1_1resultset.html#ad28608b9530c9de5cb0b9f1b87a7e785',1,'db::resultset']]] ]; diff --git a/docs/search/variables_2.js b/docs/search/variables_2.js index ad1f660..509eddb 100644 --- a/docs/search/variables_2.js +++ b/docs/search/variables_2.js @@ -1,4 +1,4 @@ var searchData= [ - ['rows_60',['rows',['../structdb_1_1resultset.html#a86664b2b52696b3732e21453851dae5b',1,'db::resultset']]] + ['rows_61',['rows',['../structdb_1_1resultset.html#a86664b2b52696b3732e21453851dae5b',1,'db::resultset']]] ]; diff --git a/docs/structdb_1_1resultset-members.html b/docs/structdb_1_1resultset-members.html index 195de45..1d5f43d 100644 --- a/docs/structdb_1_1resultset-members.html +++ b/docs/structdb_1_1resultset-members.html @@ -106,7 +106,7 @@ diff --git a/docs/structdb_1_1resultset.html b/docs/structdb_1_1resultset.html index 447a714..828f673 100644 --- a/docs/structdb_1_1resultset.html +++ b/docs/structdb_1_1resultset.html @@ -446,7 +446,7 @@

    - +
diff --git a/docs/xml/_r_e_a_d_m_e_8md.xml b/docs/xml/_r_e_a_d_m_e_8md.xml new file mode 100644 index 0000000..64a1bd7 --- /dev/null +++ b/docs/xml/_r_e_a_d_m_e_8md.xml @@ -0,0 +1,11 @@ + + + + README.md + + + + + + + diff --git a/docs/xml/index.xml b/docs/xml/index.xml index 4872a25..d495ac3 100644 --- a/docs/xml/index.xml +++ b/docs/xml/index.xml @@ -44,6 +44,10 @@ database.h + README.md + deprecated + index + diff --git a/docs/xml/indexpage.xml b/docs/xml/indexpage.xml new file mode 100644 index 0000000..7266ca7 --- /dev/null +++ b/docs/xml/indexpage.xml @@ -0,0 +1,108 @@ + + + + index + A simple asynchronous MySQL wrapper for D++ bots + + + + Simply take the source files and add them to your D++ bot project. This is a slightly modified version of what is used in my own bots. +This wrapper supports both synchronous (blocking) API and asynchronous (coroutine) API, alongside callback based async. All queries done through this wrapper use cached prepared statements, this will consume a very small amount of ram for a sometimes drastic increase in performance. +It is thread safe, however be aware that different threads may run queries that may intrude into other threads transactions. If you need ACID transaction safety, you should only use db::co_transaction() or db::transaction() and ensure all queries within use db::query(). +No support is offered for this software at present. Your mileage may vary. I have only ever used this wrapper on Linux. +Detecting and linking the dependencies (libmysqlclient.so etc) is currently your responsibility. No package mangagement or build script is provided. + +Documentation +Doxygen documentation can be found on github pages. It can be re-generated by running 'doxygen' + + +Dependencies + +libmysqlclient-dev +D++ +fmtlib +A C++ compiler capable of building D++ bots with coroutine support, if you want to use the asynchronous interface + + + + +Documentation +All functions in the db namespace have Doxygen comment blocks. + + +Using the wrapper + +Simple Queries +This is an example of using the asynchronous interface: +#include<dpp/dpp.h> +#include"database.h" +#include"config.h" + +intmain(intargc,charconst*argv[]){ +config::init("config.json"); +dpp::clusterbot(config::get("token")); + +bot.on_ready([&bot](constdpp::ready_t&event)->dpp::task<void>{ + +autors=co_awaitdb::co_query("SELECT*FROMbigtableWHEREbar=?",{"baz"}); +if(!rs.ok()){ +std::cout<<"SQLerror:"<<rs.error<<"\n"; +co_return; +} + +std::cout<<"Numberofrowsreturned:"<<rs.size()<<"\n"; +if(!rs.empty()){ +std::cout<<"Firstrow'bar'value:"<<rs[0].at("bar")<<"\n"; +} + +co_return; +}); + +db::init(bot); +bot.start(dpp::st_wait); +} + +Also create a config.json file. To use unix sockets to connect, set the port value to 0 and the hostname value to localhost. +{ +"token":"discordbottoken", +"database":{ +"host":"hostname", +"username":"databaseusername", +"password":"databasepassword", +"database":"schemaname", +"port":0, +"socket":"/path/to/mysqld.sock" +} +} + + + +Using Transactions +To use transactions, wrap the transaction in the db::transaction function, and use only the db::query function within it for queries. Return true to commit the transaction, or throw any exception or return false to roll back the transaction. +Note that during a transaction all other queries will be forced to wait until the transaction is completed. Transactions are asynchronous, so use the callback to be notified when it completes, or use co_transaction as below: +#include<dpp/dpp.h> +#include"database.h" +#include"config.h" + +intmain(intargc,charconst*argv[]){ +config::init("config.json"); +dpp::clusterbot(config::get("token")); + +bot.on_ready([&bot](constdpp::ready_t&event)->dpp::task<void>{ +co_awaitdb::co_transaction([event]()->bool{ +autors=db::query("SELECTcurrentFROMdata"); +db::query("UPDATEdataSETprevious=?",{rs[0].at("data")}); +returntrue; +}); +}); + +db::init(bot); +bot.start(dpp::st_wait); +} + + + + + + +