added sqlite connection class (progress)

This commit is contained in:
2023-11-07 23:07:49 +01:00
parent f4f5c00eec
commit 715f4dff8f
21 changed files with 645 additions and 73 deletions
+4 -2
View File
@@ -9,7 +9,9 @@ FetchContent_Declare(
FetchContent_MakeAvailable(Catch2)
add_executable(tests builder.cpp
connection.cpp
record.cpp)
session.cpp
record.cpp
connection_pool.cpp
query.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain matador)
target_include_directories(tests PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/include)
+42
View File
@@ -0,0 +1,42 @@
#include <catch2/catch_test_macros.hpp>
#include <matador/sql/connection.hpp>
#include <matador/sql/connection_pool.hpp>
using namespace matador::sql;
TEST_CASE("Create connection pool", "[connection pool]") {
using pool_t = connection_pool<connection>;
pool_t pool("db", 4);
REQUIRE(pool.size() == 4);
REQUIRE(pool.idle() == 4);
REQUIRE(pool.inuse() == 0);
auto ptr = pool.acquire();
REQUIRE(ptr.valid());
REQUIRE(ptr->is_open());
REQUIRE(!ptr->dns().empty());
REQUIRE(pool.idle() == 3);
REQUIRE(pool.inuse() == 1);
pool.release(ptr);
REQUIRE(!ptr.valid());
REQUIRE(pool.idle() == 4);
REQUIRE(pool.inuse() == 0);
{
auto ptr2 = pool.acquire();
REQUIRE(ptr2.valid());
REQUIRE(ptr2->is_open());
REQUIRE(!ptr2->dns().empty());
REQUIRE(pool.idle() == 3);
REQUIRE(pool.inuse() == 1);
}
REQUIRE(pool.idle() == 4);
REQUIRE(pool.inuse() == 0);
}
+9
View File
@@ -0,0 +1,9 @@
#include <catch2/catch_test_macros.hpp>
#include "catch2/generators/catch_generators.hpp"
TEST_CASE("Query test", "[query]") {
auto dns = GENERATE(as<std::string>{}, "mssql", "sqlite", "postgres" );
INFO(dns);
REQUIRE(!dns.empty());
}
+25 -17
View File
@@ -2,14 +2,15 @@
#include <matador/sql/column.hpp>
#include <matador/sql/condition.hpp>
#include <matador/sql/connection.hpp>
#include <matador/sql/session.hpp>
using namespace matador::sql;
TEST_CASE("Execute create table statement", "[connection]") {
connection c;
connection_pool<connection> pool("dns", 4);
session s(pool);
const auto res = c.create()
const auto res = s.create()
.table("person", {
make_pk_column<unsigned long>("id"),
make_column<std::string>("name", 255),
@@ -21,9 +22,10 @@ TEST_CASE("Execute create table statement", "[connection]") {
}
TEST_CASE("Execute drop table statement", "[connection]") {
connection c;
connection_pool<connection> pool("dns", 4);
session s(pool);
const auto res = c.drop()
const auto res = s.drop()
.table("person")
.execute();
@@ -31,9 +33,10 @@ TEST_CASE("Execute drop table statement", "[connection]") {
}
TEST_CASE("Execute select statement with where clause", "[connection]") {
connection c;
connection_pool<connection> pool("dns", 4);
session s(pool);
auto res = c.select({"id", "name", "color"})
auto res = s.select({"id", "name", "color"})
.from("person")
.where("id"_col == 8)
.fetch_all();
@@ -42,9 +45,10 @@ TEST_CASE("Execute select statement with where clause", "[connection]") {
}
TEST_CASE("Execute select statement with order by", "[connection]") {
connection c;
connection_pool<connection> pool("dns", 4);
session s(pool);
auto res = c.select({"id", "name", "color"})
auto res = s.select({"id", "name", "color"})
.from("person")
.where("id"_col == 8)
.order_by("name").desc()
@@ -54,9 +58,10 @@ TEST_CASE("Execute select statement with order by", "[connection]") {
}
TEST_CASE("Execute select statement with group by and order by", "[connection]") {
connection c;
connection_pool<connection> pool("dns", 4);
session s(pool);
auto res = c.select({"id", "name", "color"})
auto res = s.select({"id", "name", "color"})
.from("person")
.where("id"_col == 8)
.group_by("color")
@@ -67,9 +72,10 @@ TEST_CASE("Execute select statement with group by and order by", "[connection]")
}
TEST_CASE("Execute insert statement", "[connection]") {
connection c;
connection_pool<connection> pool("dns", 4);
session s(pool);
auto res = c.insert()
auto res = s.insert()
.into("person", {"id", "name", "color"})
.values({7, "george", "green"})
.execute();
@@ -78,9 +84,10 @@ TEST_CASE("Execute insert statement", "[connection]") {
}
TEST_CASE("Execute update statement", "[connection]") {
connection c;
connection_pool<connection> pool("dns", 4);
session s(pool);
auto res = c.update("person")
auto res = s.update("person")
.set({
{"name", "george"},
{"color", "green"}
@@ -92,9 +99,10 @@ TEST_CASE("Execute update statement", "[connection]") {
}
TEST_CASE("Execute delete statement", "[connection]") {
connection c;
connection_pool<connection> pool("dns", 4);
session s(pool);
auto res = c.remove()
auto res = s.remove()
.from("person", "p")
.where("id"_col == 9)
.execute();