mirror of
https://github.com/getml/sqlgen.git
synced 2026-05-09 08:39:55 -05:00
Expand the is_connection concept to iterators (#103)
This commit is contained in:
committed by
GitHub
parent
657a9fd4ee
commit
758bb1d87e
@@ -65,7 +65,7 @@ class Session {
|
||||
}
|
||||
|
||||
template <class ContainerType>
|
||||
Result<ContainerType> read(const dynamic::SelectFrom& _query) {
|
||||
auto read(const dynamic::SelectFrom& _query) {
|
||||
return conn_->template read<ContainerType>(_query);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <class ContainerType>
|
||||
Result<ContainerType> read(const dynamic::SelectFrom& _query) {
|
||||
auto read(const dynamic::SelectFrom& _query) {
|
||||
return conn_->template read<ContainerType>(_query);
|
||||
}
|
||||
|
||||
@@ -111,4 +112,12 @@ class Transaction {
|
||||
|
||||
} // namespace sqlgen
|
||||
|
||||
namespace sqlgen::internal {
|
||||
|
||||
template <class ValueType, class Connection>
|
||||
struct IteratorType<ValueType, sqlgen::Transaction<Connection>> {
|
||||
using Type = typename IteratorType<ValueType, Connection>::Type;
|
||||
};
|
||||
|
||||
} // namespace sqlgen::internal
|
||||
#endif
|
||||
|
||||
@@ -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<Connection>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Transaction<Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
|
||||
} // namespace sqlgen::duckdb
|
||||
|
||||
namespace sqlgen::internal {
|
||||
@@ -205,6 +203,13 @@ struct IteratorType<ValueType, duckdb::Connection> {
|
||||
using Type = duckdb::Iterator<ValueType>;
|
||||
};
|
||||
|
||||
static_assert(is_connection<duckdb::Connection>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Session<duckdb::Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Transaction<duckdb::Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
|
||||
} // namespace sqlgen::internal
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "../Result.hpp"
|
||||
#include "../transpilation/value_t.hpp"
|
||||
#include "is_range.hpp"
|
||||
#include "iterator_t.hpp"
|
||||
|
||||
namespace sqlgen::internal {
|
||||
|
||||
|
||||
@@ -6,12 +6,14 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<std::vector<internal::MockTable>>(_select_from)
|
||||
} -> std::same_as<Result<std::vector<internal::MockTable>>>;
|
||||
|
||||
/// Reads the results of a SelectFrom statement as a Range.
|
||||
{
|
||||
c.template read<Range<internal::MockTable>>(_select_from)
|
||||
} -> std::same_as<
|
||||
Result<Range<internal::iterator_t<internal::MockTable, ConnType>>>>;
|
||||
|
||||
/// Commits a transaction.
|
||||
{ c.rollback() } -> std::same_as<Result<Nothing>>;
|
||||
|
||||
|
||||
@@ -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<Connection>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Transaction<Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
|
||||
} // namespace sqlgen::mysql
|
||||
|
||||
namespace sqlgen::internal {
|
||||
@@ -126,6 +122,13 @@ struct IteratorType<ValueType, mysql::Connection> {
|
||||
using Type = Iterator<ValueType, mysql::Iterator>;
|
||||
};
|
||||
|
||||
static_assert(is_connection<mysql::Connection>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Session<mysql::Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Transaction<mysql::Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
|
||||
} // namespace sqlgen::internal
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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<Connection>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Transaction<Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
|
||||
} // namespace sqlgen::postgres
|
||||
|
||||
namespace sqlgen::internal {
|
||||
@@ -118,6 +114,13 @@ struct IteratorType<ValueType, postgres::Connection> {
|
||||
using Type = Iterator<ValueType, postgres::Iterator>;
|
||||
};
|
||||
|
||||
static_assert(is_connection<postgres::Connection>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Session<postgres::Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Transaction<postgres::Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
|
||||
} // namespace sqlgen::internal
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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<Connection>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Transaction<Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
|
||||
} // namespace sqlgen::sqlite
|
||||
|
||||
namespace sqlgen::internal {
|
||||
@@ -124,6 +120,12 @@ struct IteratorType<ValueType, sqlite::Connection> {
|
||||
using Type = Iterator<ValueType, sqlite::Iterator>;
|
||||
};
|
||||
|
||||
static_assert(is_connection<sqlite::Connection>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Session<sqlite::Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
static_assert(is_connection<Transaction<sqlite::Connection>>,
|
||||
"Must fulfill the is_connection concept.");
|
||||
} // namespace sqlgen::internal
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user