Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/sqlgen/Session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 10 additions & 1 deletion include/sqlgen/Transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define SQLGEN_TRANSACTION_HPP_

#include "Ref.hpp"
#include "internal/iterator_t.hpp"
#include "is_connection.hpp"

namespace sqlgen {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
19 changes: 12 additions & 7 deletions include/sqlgen/duckdb/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
1 change: 1 addition & 0 deletions include/sqlgen/internal/to_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../Result.hpp"
#include "../transpilation/value_t.hpp"
#include "is_range.hpp"
#include "iterator_t.hpp"

namespace sqlgen::internal {

Expand Down
8 changes: 8 additions & 0 deletions include/sqlgen/is_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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>>;

Expand Down
13 changes: 8 additions & 5 deletions include/sqlgen/mysql/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 changes: 8 additions & 5 deletions include/sqlgen/postgres/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 changes: 7 additions & 5 deletions include/sqlgen/sqlite/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Loading