diff --git a/include/sqlgen/write.hpp b/include/sqlgen/write.hpp index fbf7cde..10a8202 100644 --- a/include/sqlgen/write.hpp +++ b/include/sqlgen/write.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -13,6 +14,7 @@ #include "Result.hpp" #include "internal/batch_size.hpp" #include "internal/to_str_vec.hpp" +#include "transpilation/has_value_type.hpp" #include "transpilation/to_create_table.hpp" #include "transpilation/to_insert.hpp" @@ -71,7 +73,11 @@ auto write(const Result>& _res, ItBegin _begin, template auto write(const ConnectionType& _conn, const ContainerType& _container) noexcept { - return write(_conn, _container.begin(), _container.end()); + if constexpr (std::ranges::input_range>) { + return write(_conn, _container.begin(), _container.end()); + } else { + return write(_conn, &_container, &_container + 1); + } } } // namespace sqlgen diff --git a/tests/sqlite/test_hello_world.cpp b/tests/sqlite/test_hello_world.cpp new file mode 100644 index 0000000..39a7b76 --- /dev/null +++ b/tests/sqlite/test_hello_world.cpp @@ -0,0 +1,32 @@ +#include + +#include +#include +#include +#include +#include + +namespace test_hello_world { + +struct User { + std::string name; + int age; +}; + +TEST(sqlite, test_hello_world) { + // Connect to SQLite database + const auto conn = sqlgen::sqlite::connect("test.db"); + + // Create and insert a user + const auto user = User{.name = "John", .age = 30}; + sqlgen::write(conn, user); + + // Read all users + const auto users = sqlgen::read>(conn).value(); + + EXPECT_EQ(users.size(), 1); + EXPECT_EQ(users.at(0).name, "John"); + EXPECT_EQ(users.at(0).age, 30); +} + +} // namespace test_hello_world