feat(sqlite): harden Sqlite lifecycle/transactions/migrations/ops and add SqliteAsync pool
This commit is contained in:
1 parent
9925ea1764
commit
427cc9a843
15 files changed
+4438
-134
No files matched your search
@@ -214,6 +214,24 @@ if(_has_update)
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_SQLite3=TRUE)
|
||||
endif()
|
||||
|
||||
has_modules(_has_sqlite Sqlite Functional Time)
|
||||
if(_has_sqlite)
|
||||
run_consumer(SqliteOnly "${install_prefix}" "SqliteOnly"
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_LibArchive=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_OpenSSL=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=TRUE)
|
||||
endif()
|
||||
|
||||
has_modules(_has_sqlite_async SqliteAsync Sqlite Async Time Functional LogState)
|
||||
if(_has_sqlite_async)
|
||||
run_consumer(SqliteAsyncOnly "${install_prefix}" "SqliteAsyncOnly"
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_LibArchive=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_OpenSSL=TRUE
|
||||
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=TRUE)
|
||||
endif()
|
||||
|
||||
# Foundation consumer with Core-formatting bridge and zero external packages.
|
||||
has_modules(_has_foundation Math Text Time Functional Binary FunctionalCoreFormatting Memory Core)
|
||||
if(_has_foundation)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
project(VoidSqliteAsyncOnlyConsumer LANGUAGES CXX)
|
||||
|
||||
find_package(Void CONFIG REQUIRED COMPONENTS SqliteAsync)
|
||||
|
||||
add_executable(void_sqlite_async_only_consumer main.cpp)
|
||||
target_link_libraries(void_sqlite_async_only_consumer PRIVATE Void::SqliteAsync)
|
||||
target_compile_features(void_sqlite_async_only_consumer PRIVATE cxx_std_26)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME SqliteAsyncOnlyConsumer COMMAND void_sqlite_async_only_consumer)
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <Void/Sqlite/AsyncPool.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto dir = std::filesystem::temp_directory_path() /
|
||||
("void-sqlite-async-pkg-" + std::to_string(::getpid()));
|
||||
std::error_code ec;
|
||||
std::filesystem::remove_all(dir, ec);
|
||||
std::filesystem::create_directories(dir, ec);
|
||||
|
||||
Void::Sqlite::AsyncPoolOptions opts;
|
||||
opts.path = dir / "pkg.db";
|
||||
opts.reader_connections = 2;
|
||||
auto pool = Void::Sqlite::AsyncPool::open(opts);
|
||||
const bool ok = pool.has_value() && pool->stats().reader_connections == 2 &&
|
||||
pool->close_and_join().has_value();
|
||||
std::filesystem::remove_all(dir, ec);
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
project(VoidSqliteOnlyConsumer LANGUAGES CXX)
|
||||
|
||||
find_package(Void CONFIG REQUIRED COMPONENTS Sqlite)
|
||||
|
||||
add_executable(void_sqlite_only_consumer main.cpp)
|
||||
target_link_libraries(void_sqlite_only_consumer PRIVATE Void::Sqlite)
|
||||
target_compile_features(void_sqlite_only_consumer PRIVATE cxx_std_26)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME SqliteOnlyConsumer COMMAND void_sqlite_only_consumer)
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <Void/Sqlite/Sqlite.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
Void::Sqlite::OpenOptions opts;
|
||||
auto db = Void::Sqlite::open_database(":memory:", opts);
|
||||
if (!db) return 1;
|
||||
if (!db->exec("CREATE TABLE t(id INTEGER PRIMARY KEY)").has_value()) return 2;
|
||||
auto tx = db->begin(Void::Sqlite::BeginMode::Immediate);
|
||||
if (!tx) return 3;
|
||||
auto st = db->prepare("INSERT INTO t(id) VALUES(?)");
|
||||
if (!st) return 4;
|
||||
if (!st->bind_checked(1, Void::Sqlite::ValueView{7}).has_value()) return 5;
|
||||
if (!st->step().has_value()) return 6;
|
||||
if (!st->finalize_checked().has_value()) return 7;
|
||||
if (!tx->commit().has_value()) return 8;
|
||||
if (!db->close().has_value()) return 9;
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user