diff --git a/include/sqlgen/Session.hpp b/include/sqlgen/Session.hpp index 4e079d7..353f0d2 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 7d1ae5b..b980dca 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 12db37f..b348bbc 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) { @@ -192,11 +195,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 +203,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 ceaacbc..4f7262f 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 e526a7f..1aa7b6d 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 4bf62d5..323162e 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 77924f1..abaee34 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 ec04dd0..670f276 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