2424namespace 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 {
4040public:
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 {
151151public:
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
0 commit comments