Skip to content

Commit 8fba819

Browse files
Pierre-Luc Gagnéclaude
andcommitted
docs: update README and CLAUDE.md for v4.0.0 API changes
- Update all code examples to instance-based API (create_table(T{}), select(col{}), from(T{}), etc.) - Document execute() returning uint64_t affected row count - Document new mysql_connection methods and connect_options - Add charset_name and connect_options.hpp to header layout - Fix truncate<T>() → truncate_table(T{}) in DML examples Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6fa4dfb commit 8fba819

2 files changed

Lines changed: 29 additions & 27 deletions

File tree

CLAUDE.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ Style: Google-based, 120-char line limit, 4-space indent (`.clang-format` at roo
4747
### Header Layout (`lib/include/ds_mysql/`)
4848

4949
- `ds_mysql.hpp` — umbrella include; users include only this
50-
- `mysql_connection.hpp``mysql_config` and `mysql_connection` classes; `.query()` returns `std::expected<ResultType, std::string>`, `.execute()` for DDL/DML
51-
- `sql_ddl.hpp``create_table<T>()`, `drop_table<T>()`, `create_database<DB>()`, `create_all_tables<DB>()`
52-
- `sql_dml.hpp``insert_into<T>()`, `update<T>()`, `delete_from<T>()`, `truncate<T>()`
53-
- `sql_dql.hpp``select<...>()`, `count<T>()`, `describe<T>()`
50+
- `mysql_connection.hpp``mysql_config`, `connect_options`, and `mysql_connection` classes; `.query()` returns `std::expected<ResultType, std::string>`, `.execute()` returns `std::expected<uint64_t, std::string>` (affected row count); also provides `last_insert_id()`, `ping()`, `commit()`, `rollback()`, `autocommit()`, `select_db()`, `reset_connection()`, `escape_string()`, `warning_count()`, `info()`, `server_version()`, `server_info()`, `stat()`, `thread_id()`, `character_set()`, `set_character_set()`
51+
- `sql_ddl.hpp``create_table(T{})`, `drop_table(T{})`, `create_database(DB{})`, `create_all_tables(DB{})`
52+
- `sql_dml.hpp``insert_into(T{})`, `update(T{})`, `delete_from(T{})`, `truncate_table(T{})`
53+
- `sql_dql.hpp``select(col1{}, col2{})`, `count(T{})`, `describe(T{})`
54+
- `connect_options.hpp``connect_options` fluent builder and `ssl_mode` enum for pre-connect `mysql_options()` configuration (timeouts, SSL/TLS, charset, compression, etc.)
55+
- `charset_name.hpp``charset_name` strong type for character set names
5456
- `column_field.hpp` / `column_field_base_*.hpp``column_field<"name", Type>` descriptors and `COLUMN_FIELD(name, type)` macro
5557
- `schema_generator.hpp` — derives CREATE TABLE SQL from a C++ struct at compile time using Boost.PFR
5658
- `sql_varchar.hpp`, `sql_numeric.hpp`, `sql_temporal.hpp` — library-specific SQL types (`varchar_type<N>`, `decimal_type<P,S>`, `datetime_type<FSP>`, etc.)
@@ -61,7 +63,7 @@ Style: Google-based, 120-char line limit, 4-space indent (`.clang-format` at roo
6163
- Native C++ types map directly: `int32_t` → INT, `int64_t` → BIGINT, `double` → DOUBLE, `std::string` → TEXT
6264
- `std::optional<T>` → nullable column
6365
- `varchar_type<N>` → VARCHAR(N); `decimal_type<P,S>` → DECIMAL(P,S)
64-
- Strong-typed wrappers (`host_name`, `database_name`, `port_number`) enforce correct argument passing
66+
- Strong-typed wrappers (`host_name`, `database_name`, `port_number`, `charset_name`) enforce correct argument passing
6567

6668
### Schema Generation and Validation
6769

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct product {
6161
// c) Fixed string literal — column name embedded directly, no tag needed.
6262
// ⚠ Two tables with identically-named and -typed columns share the same C++ type,
6363
// so column_field cannot verify which table a column belongs to. This means
64-
// column_field columns cannot be used as select projections in from<Table>().
64+
// from() cannot verify column membership for untagged column_field types.
6565
// Prefer COLUMN_FIELD or explicit nested tags for query-building use cases.
6666
// using price = column_field<"price", double>;
6767
// price price_;
@@ -79,13 +79,13 @@ auto db = mysql_connection::connect(mysql_config{
7979
}).value();
8080

8181
// CREATE TABLE IF NOT EXISTS product (...)
82-
db.execute(create_table<product>().if_not_exists());
82+
db.execute(create_table(product{}).if_not_exists());
8383

8484
// Type-safe SELECT: returns std::expected<std::vector<std::tuple<uint32_t, varchar_type<255>>>, std::string>
85-
auto rows = db.query(select<product::id, product::name>()
86-
.from<product>()
87-
.where(product::price{9.99})
88-
.order_by<product::id>());
85+
auto rows = db.query(select(product::id{}, product::name{})
86+
.from(product{})
87+
.where(equal<product::price>(9.99))
88+
.order_by(product::id{}));
8989

9090
for (auto const& [id, name] : *rows) {
9191
std::println("{}: {}", id, name.to_string());
@@ -201,15 +201,15 @@ auto db = mysql_connection::connect(cfg).value();
201201
### DDL (CREATE, DROP)
202202
203203
```cpp
204-
db.execute(create_table<product>().if_not_exists());
205-
db.execute(drop_table<product>());
206-
db.execute(create_database<my_db>().if_not_exists());
204+
db.execute(create_table(product{}).if_not_exists());
205+
db.execute(drop_table(product{}));
206+
db.execute(create_database(my_db{}).if_not_exists());
207207
```
208208

209209
#### CREATE TABLE attributes (fluent API)
210210

211211
```cpp
212-
auto sql = create_table<product>()
212+
auto sql = create_table(product{})
213213
.if_not_exists()
214214
.engine(Engine::InnoDB)
215215
.auto_increment(1)
@@ -218,8 +218,8 @@ auto sql = create_table<product>()
218218
.comment("product catalog")
219219
.build_sql();
220220

221-
auto ctas = create_table<product_archive>()
222-
.as(select<product::id, product::name>().from<product>())
221+
auto ctas = create_table(product_archive{})
222+
.as(select(product::id{}, product::name{}).from(product{}))
223223
.engine("MyCustomEngine")
224224
.default_charset("koi8r")
225225
.build_sql();
@@ -228,28 +228,28 @@ auto ctas = create_table<product_archive>()
228228
### DML (INSERT, UPDATE, DELETE)
229229

230230
```cpp
231-
db.execute(insert_into<product>().values(row));
232-
db.execute(update<product>().set(product::price{12.99}).where(product::id{1}));
233-
db.execute(delete_from<product>().where(product::id{1}));
234-
db.execute(truncate<product>());
231+
db.execute(insert_into(product{}).values(row));
232+
db.execute(update(product{}).set(product::price{12.99}).where(equal<product::id>(1u)));
233+
db.execute(delete_from(product{}).where(equal<product::id>(1u)));
234+
db.execute(truncate_table(product{}));
235235
```
236236
237237
### DQL (SELECT, COUNT, DESCRIBE)
238238
239239
```cpp
240240
// Select specific columns
241-
auto rows = db.query(select<product::id, product::name>().from<product>());
241+
auto rows = db.query(select(product::id{}, product::name{}).from(product{}));
242242
243243
// Select all columns
244-
auto all = db.query(select<product::id, product::sku, product::name, product::price>()
245-
.from<product>()
246-
.order_by<product::id>());
244+
auto all = db.query(select(product::id{}, product::sku{}, product::name{}, product::price{})
245+
.from(product{})
246+
.order_by(product::id{}));
247247
248248
// Count
249-
auto cnt = db.query(count<product>().where(product::price{9.99}));
249+
auto cnt = db.query(count(product{}).where(equal<product::price>(9.99)));
250250
251251
// DESCRIBE (schema introspection)
252-
auto cols = db.query(describe<product>());
252+
auto cols = db.query(describe(product{}));
253253
```
254254

255255
### Schema Validation

0 commit comments

Comments
 (0)