From 52b3a899949501322e60b3d14580ca0f6c300cca Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Sun, 30 Nov 2025 15:46:18 +0100 Subject: [PATCH 1/2] Make sure that Transaction also work with iterators and expand the is_connection concept --- include/sqlgen/Session.hpp | 2 +- include/sqlgen/Transaction.hpp | 11 ++++++++++- include/sqlgen/duckdb/Connection.hpp | 12 +++++++----- include/sqlgen/internal/to_container.hpp | 1 + include/sqlgen/is_connection.hpp | 8 ++++++++ include/sqlgen/mysql/Connection.hpp | 13 ++++++++----- include/sqlgen/postgres/Connection.hpp | 13 ++++++++----- include/sqlgen/sqlite/Connection.hpp | 12 +++++++----- 8 files changed, 50 insertions(+), 22 deletions(-) diff --git a/include/sqlgen/Session.hpp b/include/sqlgen/Session.hpp index 4e079d74..353f0d25 100644 --- a/include/sqlgen/Session.hpp +++ b/include/sqlgen/Session.hpp @@ -65,7 +65,7 @@ class Session { } template - Result read(const dynamic::SelectFrom& _query) { + auto read(const dynamic::SelectFrom& _query) { return conn_->template read(_query); } diff --git a/include/sqlgen/Transaction.hpp b/include/sqlgen/Transaction.hpp index 7d1ae5bc..b980dcae 100644 --- a/include/sqlgen/Transaction.hpp +++ b/include/sqlgen/Transaction.hpp @@ -2,6 +2,7 @@ #define SQLGEN_TRANSACTION_HPP_ #include "Ref.hpp" +#include "internal/iterator_t.hpp" #include "is_connection.hpp" namespace sqlgen { @@ -74,7 +75,7 @@ class Transaction { } template - Result read(const dynamic::SelectFrom& _query) { + auto read(const dynamic::SelectFrom& _query) { return conn_->template read(_query); } @@ -111,4 +112,12 @@ class Transaction { } // namespace sqlgen +namespace sqlgen::internal { + +template +struct IteratorType> { + using Type = typename IteratorType::Type; +}; + +} // namespace sqlgen::internal #endif diff --git a/include/sqlgen/duckdb/Connection.hpp b/include/sqlgen/duckdb/Connection.hpp index 19d9b7af..988c91fc 100644 --- a/include/sqlgen/duckdb/Connection.hpp +++ b/include/sqlgen/duckdb/Connection.hpp @@ -192,11 +192,6 @@ class SQLGEN_API Connection { ConnPtr conn_; }; -static_assert(is_connection, - "Must fulfill the is_connection concept."); -static_assert(is_connection>, - "Must fulfill the is_connection concept."); - } // namespace sqlgen::duckdb namespace sqlgen::internal { @@ -205,6 +200,13 @@ struct IteratorType { using Type = duckdb::Iterator; }; +static_assert(is_connection, + "Must fulfill the is_connection concept."); +static_assert(is_connection>, + "Must fulfill the is_connection concept."); +static_assert(is_connection>, + "Must fulfill the is_connection concept."); + } // namespace sqlgen::internal #endif diff --git a/include/sqlgen/internal/to_container.hpp b/include/sqlgen/internal/to_container.hpp index ceaacbc1..4f7262f3 100644 --- a/include/sqlgen/internal/to_container.hpp +++ b/include/sqlgen/internal/to_container.hpp @@ -6,6 +6,7 @@ #include "../Result.hpp" #include "../transpilation/value_t.hpp" #include "is_range.hpp" +#include "iterator_t.hpp" namespace sqlgen::internal { diff --git a/include/sqlgen/is_connection.hpp b/include/sqlgen/is_connection.hpp index e526a7f5..1aa7b6dc 100644 --- a/include/sqlgen/is_connection.hpp +++ b/include/sqlgen/is_connection.hpp @@ -6,12 +6,14 @@ #include #include +#include "Range.hpp" #include "Ref.hpp" #include "Result.hpp" #include "dynamic/SelectFrom.hpp" #include "dynamic/Statement.hpp" #include "dynamic/Write.hpp" #include "internal/MockTable.hpp" +#include "internal/iterator_t.hpp" namespace sqlgen { @@ -41,6 +43,12 @@ concept is_connection = requires( c.template read>(_select_from) } -> std::same_as>>; + /// Reads the results of a SelectFrom statement as a Range. + { + c.template read>(_select_from) + } -> std::same_as< + Result>>>; + /// Commits a transaction. { c.rollback() } -> std::same_as>; diff --git a/include/sqlgen/mysql/Connection.hpp b/include/sqlgen/mysql/Connection.hpp index 4bf62d5a..323162e7 100644 --- a/include/sqlgen/mysql/Connection.hpp +++ b/include/sqlgen/mysql/Connection.hpp @@ -11,6 +11,7 @@ #include "../Iterator.hpp" #include "../Ref.hpp" #include "../Result.hpp" +#include "../Session.hpp" #include "../Transaction.hpp" #include "../dynamic/Column.hpp" #include "../dynamic/Insert.hpp" @@ -112,11 +113,6 @@ class SQLGEN_API Connection { ConnPtr conn_; }; -static_assert(is_connection, - "Must fulfill the is_connection concept."); -static_assert(is_connection>, - "Must fulfill the is_connection concept."); - } // namespace sqlgen::mysql namespace sqlgen::internal { @@ -126,6 +122,13 @@ struct IteratorType { using Type = Iterator; }; +static_assert(is_connection, + "Must fulfill the is_connection concept."); +static_assert(is_connection>, + "Must fulfill the is_connection concept."); +static_assert(is_connection>, + "Must fulfill the is_connection concept."); + } // namespace sqlgen::internal #endif diff --git a/include/sqlgen/postgres/Connection.hpp b/include/sqlgen/postgres/Connection.hpp index 77924f1d..abaee344 100644 --- a/include/sqlgen/postgres/Connection.hpp +++ b/include/sqlgen/postgres/Connection.hpp @@ -13,6 +13,7 @@ #include "../Iterator.hpp" #include "../Ref.hpp" #include "../Result.hpp" +#include "../Session.hpp" #include "../Transaction.hpp" #include "../dynamic/Column.hpp" #include "../dynamic/Insert.hpp" @@ -104,11 +105,6 @@ class SQLGEN_API Connection { Conn conn_; }; -static_assert(is_connection, - "Must fulfill the is_connection concept."); -static_assert(is_connection>, - "Must fulfill the is_connection concept."); - } // namespace sqlgen::postgres namespace sqlgen::internal { @@ -118,6 +114,13 @@ struct IteratorType { using Type = Iterator; }; +static_assert(is_connection, + "Must fulfill the is_connection concept."); +static_assert(is_connection>, + "Must fulfill the is_connection concept."); +static_assert(is_connection>, + "Must fulfill the is_connection concept."); + } // namespace sqlgen::internal #endif diff --git a/include/sqlgen/sqlite/Connection.hpp b/include/sqlgen/sqlite/Connection.hpp index ec04dd08..670f2769 100644 --- a/include/sqlgen/sqlite/Connection.hpp +++ b/include/sqlgen/sqlite/Connection.hpp @@ -12,6 +12,7 @@ #include "../Iterator.hpp" #include "../Ref.hpp" #include "../Result.hpp" +#include "../Session.hpp" #include "../Transaction.hpp" #include "../dynamic/SelectFrom.hpp" #include "../dynamic/Union.hpp" @@ -110,11 +111,6 @@ class SQLGEN_API Connection { ConnPtr conn_; }; -static_assert(is_connection, - "Must fulfill the is_connection concept."); -static_assert(is_connection>, - "Must fulfill the is_connection concept."); - } // namespace sqlgen::sqlite namespace sqlgen::internal { @@ -124,6 +120,12 @@ struct IteratorType { using Type = Iterator; }; +static_assert(is_connection, + "Must fulfill the is_connection concept."); +static_assert(is_connection>, + "Must fulfill the is_connection concept."); +static_assert(is_connection>, + "Must fulfill the is_connection concept."); } // namespace sqlgen::internal #endif From 66f83ef69e32bd508a2c7f598e9e4b702a090649 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Sat, 6 Dec 2025 21:39:17 +0100 Subject: [PATCH 2/2] Added missing include --- include/sqlgen/duckdb/Connection.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/sqlgen/duckdb/Connection.hpp b/include/sqlgen/duckdb/Connection.hpp index 45c431ed..b348bbc4 100644 --- a/include/sqlgen/duckdb/Connection.hpp +++ b/include/sqlgen/duckdb/Connection.hpp @@ -15,6 +15,7 @@ #include "../Range.hpp" #include "../Ref.hpp" #include "../Result.hpp" +#include "../Session.hpp" #include "../Transaction.hpp" #include "../dynamic/Operation.hpp" #include "../dynamic/SelectFrom.hpp" @@ -138,8 +139,10 @@ class SQLGEN_API Connection { .as = std::nullopt}; })); - const auto select_from = dynamic::SelectFrom{ - .table_or_query = _table, .fields = fields, .limit = dynamic::Limit{0}, .offset = dynamic::Offset{0}}; + const auto select_from = dynamic::SelectFrom{.table_or_query = _table, + .fields = fields, + .limit = dynamic::Limit{0}, + .offset = dynamic::Offset{0}}; return DuckDBResult::make(to_sql(select_from), conn_) .transform([&](const auto &_res) {