Compare commits

..

3 Commits

Author SHA1 Message Date
Sascha Kühl 61a80d93f7 use result chaining in demo::main.cpp 2025-02-04 15:38:30 +01:00
Sascha Kühl 98af2bc6c4 marked schema::attach methods as no-discard 2025-02-04 15:38:01 +01:00
Sascha Kühl 405f158a88 fixed result for void 2025-02-04 15:37:39 +01:00
3 changed files with 11 additions and 8 deletions

View File

@ -156,16 +156,19 @@ QUERY_HELPER( temporary_table, id );
int main() { int main() {
using namespace matador::sql; using namespace matador::sql;
using namespace matador::object; using namespace matador::object;
using namespace matador::utils;
const std::string env_var{"MATADOR_BACKENDS_PATH"}; const std::string env_var{"MATADOR_BACKENDS_PATH"};
std::string dns{"sqlite://demo.db"}; std::string dns{"sqlite://demo.db"};
schema s( "main" ); schema s( "main" );
s.attach<author>( "authors" ); auto result = s.attach<author>( "authors" ).and_then( [&s] {
s.attach<book>( "books" ); return s.attach<book>( "books" );
} );
// s.attach<book>( "books" );
connection c( dns ); connection c( dns );
auto result = c.open(); result = c.open();
// s.create( c ); // s.create( c );
// //
// auto create_authors_sql = c.query( s ) // auto create_authors_sql = c.query( s )

View File

@ -24,7 +24,7 @@ public:
explicit schema( const std::string& name = ""); explicit schema( const std::string& name = "");
template <typename Type> template <typename Type>
utils::result<void, utils::error> attach(const std::string name, const std::string &parent = "") { [[nodiscard]] utils::result<void, utils::error> attach(const std::string name, const std::string &parent = "") {
auto node = schema_node::make_node<Type>(*this, name); auto node = schema_node::make_node<Type>(*this, name);
auto result = attach_node(node, parent); auto result = attach_node(node, parent);
@ -36,7 +36,7 @@ public:
} }
template <typename Type, typename ParentType> template <typename Type, typename ParentType>
utils::result<void, utils::error> attach(const std::string name) { [[nodiscard]] utils::result<void, utils::error> attach(const std::string name) {
auto node = schema_node::make_node<Type>(*this, name); auto node = schema_node::make_node<Type>(*this, name);
auto result = attach_node(node, std::type_index(typeid(ParentType))); auto result = attach_node(node, std::type_index(typeid(ParentType)));

View File

@ -156,7 +156,7 @@ public:
[[nodiscard]] bool is_ok() const { return !result_.has_value(); } [[nodiscard]] bool is_ok() const { return !result_.has_value(); }
[[nodiscard]] bool is_error() const { return result_.has_value(); } [[nodiscard]] bool is_error() const { return result_.has_value(); }
ErrorType&& release_error() { return result_->release(); } ErrorType&& release_error() { return std::move(*result_); }
const ErrorType& err() const { return result_.value(); } const ErrorType& err() const { return result_.value(); }
ErrorType err() { return result_.value(); } ErrorType err() { return result_.value(); }
@ -167,7 +167,7 @@ public:
return result<SecondValueType, ErrorType>(ok(f())); return result<SecondValueType, ErrorType>(ok(f()));
} }
return result<SecondValueType, ErrorType>(error(release_error())); return result<SecondValueType, ErrorType>(failure(release_error()));
} }
template<typename Func> template<typename Func>
@ -176,7 +176,7 @@ public:
return f(); return f();
} }
return result(error(release_error())); return result(failure(release_error()));
} }
template<typename Func, typename SecondErrorType = typename std::invoke_result_t<Func, ErrorType >::value_type> template<typename Func, typename SecondErrorType = typename std::invoke_result_t<Func, ErrorType >::value_type>