Skip to content

Commit 6eb2524

Browse files
author
Pierre-Luc Gagné
committed
Rename mysql_database to mysql_connection and raw_sql to sql_raw
1 parent f7ae4e3 commit 6eb2524

9 files changed

Lines changed: 496 additions & 77 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct product {
6767
// preventing accidental cross-table column mixing.
6868

6969
// 2. Connect and query
70-
auto db = mysql_database::connect(mysql_config{
70+
auto db = mysql_connection::connect(mysql_config{
7171
host_name{"127.0.0.1"},
7272
database_name{"my_db"},
7373
auth_credentials{user_name{"root"}, user_password{"secret"}},
@@ -180,7 +180,7 @@ stable wrapper/fallback. In CMake builds, a generated
180180

181181
```cpp
182182
// Explicit parameters
183-
auto db = mysql_database::connect(
183+
auto db = mysql_connection::connect(
184184
host_name{"127.0.0.1"},
185185
database_name{"my_db"},
186186
auth_credentials{user_name{"root"}, user_password{"secret"}},
@@ -191,7 +191,7 @@ auto db = mysql_database::connect(
191191
mysql_config cfg{host_name{"127.0.0.1"}, database_name{"my_db"},
192192
auth_credentials{user_name{"root"}, user_password{""}},
193193
port_number{3306}};
194-
auto db = mysql_database::connect(cfg).value();
194+
auto db = mysql_connection::connect(cfg).value();
195195
```
196196
197197
### DDL (CREATE, DROP)

docs/DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ DSMySQL is a header-only library. All functionality lives in `lib/include/ds_mys
2727
1. Create a new header under `lib/include/ds_mysql/`
2828
2. Use `#pragma once`
2929
3. Put all code in the `ds_mysql` namespace
30-
4. Include it transitively through `ds_mysql/database.hpp`, `ds_mysql/metadata.hpp`, `ds_mysql/sql_ddl.hpp`, `ds_mysql/sql_dml.hpp`, or `ds_mysql/sql_dql.hpp` if appropriate (these are pulled in by the `ds_mysql/ds_mysql.hpp` umbrella header)
30+
4. Include it transitively through `ds_mysql/mysql_connection.hpp`, `ds_mysql/metadata.hpp`, `ds_mysql/sql_ddl.hpp`, `ds_mysql/sql_dml.hpp`, or `ds_mysql/sql_dql.hpp` if appropriate (these are pulled in by the `ds_mysql/ds_mysql.hpp` umbrella header)
3131

3232
## Adding Unit Tests
3333

docs/QUICKREF.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ DSMySQL/
4949
| Header | Purpose |
5050
| ------ | ------- |
5151
| `ds_mysql.hpp` | **Umbrella header** — include this to get everything |
52-
| `ds_mysql/database.hpp` | MySQL connection & queries |
52+
| `ds_mysql/mysql_connection.hpp` | MySQL connection & queries |
5353
| `ds_mysql/sql_ddl.hpp` | DDL query builder (CREATE / DROP / ALTER / ...) |
5454
| `ds_mysql/sql_dml.hpp` | DML query builder (INSERT / UPDATE / DELETE / DESCRIBE / ...) |
5555
| `ds_mysql/sql_dql.hpp` | DQL query builder (SELECT / projections / expressions / ...) |

examples/basic_query.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct product {
5757

5858
int main() {
5959
// --- Connect ---
60-
auto db_result = ds_mysql::mysql_database::connect(ds_mysql::mysql_config{
60+
auto db_result = ds_mysql::mysql_connection::connect(ds_mysql::mysql_config{
6161
ds_mysql::host_name{host},
6262
ds_mysql::database_name{database},
6363
ds_mysql::auth_credentials{ds_mysql::user_name{user}, ds_mysql::user_password{password}},

lib/include/ds_mysql/database.hpp

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@
2424
namespace ds_mysql {
2525

2626
// ===================================================================
27-
// raw_sql — explicit escape hatch for raw SQL strings.
27+
// sql_raw — explicit escape hatch for raw SQL strings.
2828
//
2929
// Use this only when none of the typed builders in sql_ddl.hpp, sql_dml.hpp,
3030
// or sql_dql.hpp cover your
3131
// case. Always returns std::expected<std::vector<std::vector<std::optional<std::string>>>, std::string>.
3232
// Each inner vector is a row; each element is a nullable cell value.
3333
// DDL / DML statements that produce no result set return an empty outer vector.
3434
//
35-
// db.query(raw_sql{"SELECT @@version"})
36-
// db.query(raw_sql{"DROP TABLE foo"})
35+
// db.query(sql_raw{"SELECT @@version"})
36+
// db.query(sql_raw{"DROP TABLE foo"})
3737
// ===================================================================
3838

39-
class raw_sql {
39+
class sql_raw {
4040
public:
41-
explicit raw_sql(std::string s) : sql(std::move(s)) {
41+
explicit sql_raw(std::string s) : sql(std::move(s)) {
4242
}
43-
explicit raw_sql(std::string_view s) : sql(s) {
43+
explicit sql_raw(std::string_view s) : sql(s) {
4444
}
4545
// NOLINTNEXTLINE(google-explicit-constructor)
46-
explicit raw_sql(char const* s) : sql(s) {
46+
explicit sql_raw(char const* s) : sql(s) {
4747
}
4848

4949
[[nodiscard]] std::string const& build_sql() const noexcept {
@@ -121,15 +121,15 @@ void validate_table_fields(std::vector<describe_row_type> const& rows, std::stri
121121
} // namespace detail
122122

123123
// ===================================================================
124-
// mysql_database — thin wrapper around the MySQL C API.
124+
// mysql_connection — thin wrapper around the MySQL C API.
125125
//
126126
// Provides type-safe query() and execute() methods that accept any builder
127-
// from sql_ddl.hpp, sql_dml.hpp, and sql_dql.hpp, plus a raw_sql overload
127+
// from sql_ddl.hpp, sql_dml.hpp, and sql_dql.hpp, plus a sql_raw overload
128128
// for unhandled cases.
129129
//
130130
// Factory methods:
131-
// mysql_database::connect(host, database, credentials, port)
132-
// mysql_database::connect(mysql_config)
131+
// mysql_connection::connect(host, database, credentials, port)
132+
// mysql_connection::connect(mysql_config)
133133
//
134134
// Typed query — SELECT, DESCRIBE, COUNT, aggregate queries:
135135
// db.query(select<symbol::id, symbol::ticker>().from<symbol>())
@@ -143,24 +143,24 @@ void validate_table_fields(std::vector<describe_row_type> const& rows, std::stri
143143
// → returns std::expected<void, std::string>
144144
//
145145
// Raw SQL (not type-safe — use only as a last resort):
146-
// db.query(raw_sql{"DROP TABLE foo"}) → empty vector (DDL / DML)
147-
// db.query(raw_sql{"SELECT @@version"}) → vector<vector<optional<string>>>
146+
// db.query(sql_raw{"DROP TABLE foo"}) → empty vector (DDL / DML)
147+
// db.query(sql_raw{"SELECT @@version"}) → vector<vector<optional<string>>>
148148
// ===================================================================
149149

150-
class mysql_database {
150+
class mysql_connection {
151151
public:
152-
mysql_database(mysql_database const&) = delete;
153-
mysql_database& operator=(mysql_database const&) = delete;
152+
mysql_connection(mysql_connection const&) = delete;
153+
mysql_connection& operator=(mysql_connection const&) = delete;
154154

155-
mysql_database(mysql_database&&) noexcept = default;
156-
mysql_database& operator=(mysql_database&&) noexcept = default;
157-
~mysql_database() = default;
155+
mysql_connection(mysql_connection&&) noexcept = default;
156+
mysql_connection& operator=(mysql_connection&&) noexcept = default;
157+
~mysql_connection() = default;
158158

159159
// Factory: connect with explicit parameters.
160-
[[nodiscard]] static std::expected<mysql_database, std::string> connect(host_name const& host,
161-
database_name const& database,
162-
auth_credentials const& credentials,
163-
port_number port = default_mysql_port) {
160+
[[nodiscard]] static std::expected<mysql_connection, std::string> connect(host_name const& host,
161+
database_name const& database,
162+
auth_credentials const& credentials,
163+
port_number port = default_mysql_port) {
164164
auto conn = std::unique_ptr<MYSQL, decltype(&mysql_close)>(mysql_init(nullptr), mysql_close);
165165
if (!conn) {
166166
return std::unexpected(std::string("mysql_init failed"));
@@ -172,11 +172,11 @@ class mysql_database {
172172
return std::unexpected(std::string(mysql_error(conn.get())));
173173
}
174174

175-
return mysql_database{std::move(conn)};
175+
return mysql_connection{std::move(conn)};
176176
}
177177

178178
// Factory: connect with a mysql_config object.
179-
[[nodiscard]] static std::expected<mysql_database, std::string> connect(mysql_config const& config) {
179+
[[nodiscard]] static std::expected<mysql_connection, std::string> connect(mysql_config const& config) {
180180
return connect(config.host(), config.database(), config.credentials(), config.port());
181181
}
182182

@@ -206,7 +206,7 @@ class mysql_database {
206206
// Raw SQL — not type-safe, use only when no typed builder covers the case.
207207
// Each inner vector is a row; each element is a nullable cell value.
208208
// DDL / DML statements that produce no result set return as an empty outer vector.
209-
[[nodiscard]] std::expected<std::vector<raw_result_row_type>, std::string> query(raw_sql const& stmt) const {
209+
[[nodiscard]] std::expected<std::vector<raw_result_row_type>, std::string> query(sql_raw const& stmt) const {
210210
return query(stmt.build_sql())
211211
.and_then([this]() {
212212
return store_result();
@@ -403,7 +403,7 @@ class mysql_database {
403403
...);
404404
}
405405

406-
explicit mysql_database(std::unique_ptr<MYSQL, decltype(&mysql_close)> connection)
406+
explicit mysql_connection(std::unique_ptr<MYSQL, decltype(&mysql_close)> connection)
407407
: connection_(std::move(connection)) {
408408
}
409409

@@ -414,4 +414,6 @@ class mysql_database {
414414
std::unique_ptr<MYSQL, decltype(&mysql_close)> connection_;
415415
};
416416

417+
using mysql_database = mysql_connection;
418+
417419
} // namespace ds_mysql

lib/include/ds_mysql/ds_mysql.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Convenience header — include everything needed to work with DSMySQL.
44
//
55
// Transitively provides:
6-
// database.hpp — database connection, query execution, result sets
6+
// mysql_connection.hpp — database connection, query execution, result sets
77
// sql_ddl.hpp — DDL query builder (CREATE / DROP / ALTER / ...)
88
// sql_dml.hpp — DML query builder (INSERT / UPDATE / DELETE / DESCRIBE / ...)
99
// sql_dql.hpp — DQL query builder (SELECT / projections / expressions / ...)
@@ -13,8 +13,8 @@
1313
// sql_temporal, sql_varchar, sql_text, config, credentials, …) are
1414
// pulled in transitively by the headers above.
1515

16-
#include "ds_mysql/database.hpp"
1716
#include "ds_mysql/metadata.hpp"
17+
#include "ds_mysql/mysql_connection.hpp"
1818
#include "ds_mysql/sql_ddl.hpp"
1919
#include "ds_mysql/sql_dml.hpp"
2020
#include "ds_mysql/sql_dql.hpp"

0 commit comments

Comments
 (0)