From 1c2de9b690cd35b48f2cd1fb65c613a26c9989f6 Mon Sep 17 00:00:00 2001 From: BestITUserEUW Date: Sun, 6 Jul 2025 14:58:28 +0200 Subject: [PATCH 1/6] ci updates use std::out_ptr if available allow put std::string_view into database --- .github/workflows/linux.yaml | 17 +++++++++----- include/oryx/key_value_database.hpp | 35 ++++++++++++++++++----------- tests/read_write.cpp | 1 + 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index b00d570..b0aa6e2 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -16,10 +16,12 @@ jobs: cxx: 20 - compiler: llvm compiler-version: 18 - cxx: 20 + cxx: 20 + - compiler: llvm + compiler-version: 19 + cxx: 23 - compiler: gcc compiler-version: 11 - additional-dep: "g++-11" cxx: 20 - compiler: gcc compiler-version: 12 @@ -29,9 +31,9 @@ jobs: cxx: 20 - compiler: gcc compiler-version: 14 - cxx: 20 + cxx: 23 name: "${{ github.job }} (C++${{ matrix.cxx }}-${{ matrix.compiler }}-${{ matrix.compiler-version }})" - runs-on: ubuntu-24.04 + runs-on: ubuntu-25.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -52,7 +54,12 @@ jobs: - name: Install dependencies run: | sudo apt update - sudo apt install -y ninja-build ${{ matrix.additional-dep }} + sudo apt install -y ninja-build ${{ matrix.deps }} + if [[ "${{ matrix.compiler }}" == "llvm" ]]; then + sudo apt install "clang++-${{ matrix.compiler }}" + elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then + sudo apt install "g++-${{ matrix.compiler }}" + fi - name: Compile run: | if [[ "${{ matrix.compiler }}" == "llvm" ]]; then diff --git a/include/oryx/key_value_database.hpp b/include/oryx/key_value_database.hpp index 9a4b0d3..dc828bc 100644 --- a/include/oryx/key_value_database.hpp +++ b/include/oryx/key_value_database.hpp @@ -14,6 +14,12 @@ namespace oryx { namespace detail { +template +struct is_same_r : std::bool_constant<(std::is_same_v || ...)> {}; + +template +inline constexpr bool is_same_r_v = is_same_r::value; + template constexpr auto FromChars(std::string_view s) -> std::optional { T val; @@ -33,18 +39,18 @@ constexpr auto FromChars(std::string_view s) -> std::optional { } template -auto Read(const std::string& val) -> std::optional { +constexpr auto Read(const std::string& val) -> std::optional { using _T = std::remove_cvref_t; - if constexpr (std::is_same<_T, std::string>()) { + if constexpr (std::is_same_v<_T, std::string>) return val; - } else if constexpr (std::is_same<_T, bool>()) { + else if constexpr (std::is_same_v<_T, bool>) return FromChars(val); - } else if constexpr (std::is_floating_point<_T>()) { + else if constexpr (std::is_floating_point_v<_T>) return FromChars(val); - } else if constexpr (std::is_integral<_T>()) { + else if constexpr (std::is_integral_v<_T>) return FromChars(val); - } else { + else { if (auto result = rfl::json::read(val); result) { return result.value(); } else { @@ -54,20 +60,19 @@ auto Read(const std::string& val) -> std::optional { } template -auto Write(const T& obj) -> std::string { +constexpr auto Write(const T& obj) { using _T = std::remove_cvref_t; - if constexpr (std::is_same<_T, std::string>()) { + if constexpr (is_same_r_v<_T, std::string, std::string_view>) return obj; - } else if constexpr (std::is_same<_T, bool>()) { + else if constexpr (std::is_same_v<_T, bool>) return std::to_string(static_cast(obj)); - } else if constexpr (std::is_floating_point<_T>()) { + else if constexpr (std::is_floating_point_v<_T>) return std::to_string(obj); - } else if constexpr (std::is_integral<_T>()) { + else if constexpr (std::is_integral_v<_T>) return std::to_string(obj); - } else { + else return rfl::json::write(obj); - } } } // namespace detail @@ -79,11 +84,15 @@ class KeyValueDatabase { auto Open(const std::string& name, const leveldb::Options& opts = DefaultOptions()) -> leveldb::Status { Close(); +#ifdef __cpp_lib_out_ptr + const auto status = leveldb::DB::Open(opts, name, std::out_ptr(handle_)); +#else leveldb::DB* db; const auto status = leveldb::DB::Open(opts, name, &db); if (status.ok()) { handle_ = std::unique_ptr(db); } +#endif return status; } diff --git a/tests/read_write.cpp b/tests/read_write.cpp index 02f75fb..7a39125 100644 --- a/tests/read_write.cpp +++ b/tests/read_write.cpp @@ -62,6 +62,7 @@ TEST_CASE("Reading supported types") { TEST_CASE("Writing supported types") { CHECK_EQ(detail::Write("hello world1232!*2`-."), "hello world1232!*2`-."); + CHECK_EQ(detail::Write("hello world1232!*2`-."), "hello world1232!*2`-."); CHECK_EQ(detail::Write(false), "0"); CHECK_EQ(detail::Write(true), "1"); CHECK_EQ(detail::Write(1.256), "1.256000"); // std::to_string appends 0 at the end for some reason From ae261ab01d6a5fe1f8f4c01441e645a6de449204 Mon Sep 17 00:00:00 2001 From: BestITUserEUW Date: Sun, 6 Jul 2025 15:00:01 +0200 Subject: [PATCH 2/6] fixed ci install --- .github/workflows/linux.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index b0aa6e2..48478a7 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -56,9 +56,9 @@ jobs: sudo apt update sudo apt install -y ninja-build ${{ matrix.deps }} if [[ "${{ matrix.compiler }}" == "llvm" ]]; then - sudo apt install "clang++-${{ matrix.compiler }}" + sudo apt install -y "clang++-${{ matrix.compiler }}" elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then - sudo apt install "g++-${{ matrix.compiler }}" + sudo apt install -y "g++-${{ matrix.compiler }}" fi - name: Compile run: | From df94cfa2cd8587a710d2efea75e0cde8c84242bd Mon Sep 17 00:00:00 2001 From: BestITUserEUW Date: Sun, 6 Jul 2025 18:14:25 +0200 Subject: [PATCH 3/6] move back to ubuntu 24.04 --- .github/workflows/linux.yaml | 2 +- README.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 48478a7..d9fc000 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -33,7 +33,7 @@ jobs: compiler-version: 14 cxx: 23 name: "${{ github.job }} (C++${{ matrix.cxx }}-${{ matrix.compiler }}-${{ matrix.compiler-version }})" - runs-on: ubuntu-25.04 + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 diff --git a/README.md b/README.md index 76bc23e..7cd0c2d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # ![C++](https://img.shields.io/badge/c++-%2300599C.svg?style=for-the-badge&logo=c%2B%2B&logoColor=white) kvdb-cpp +[![linux](https://github.com/BestITUserEUW/kvdb-cpp/actions/workflows/linux.yaml/badge.svg)](https://github.com/BestITUserEUW/kvdb-cpp/actions/workflows/linux.yaml) + Orm Key Value Database **kvdb-cpp** is a simple orm key value database using leveldb as db engine and reflect-cpp for providing orm support. From f1aa6541e0cb7e7dfd50517c31de27488ac196d4 Mon Sep 17 00:00:00 2001 From: BestITUserEUW Date: Sun, 6 Jul 2025 18:15:42 +0200 Subject: [PATCH 4/6] fixed install --- .github/workflows/linux.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index d9fc000..d2b462a 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -54,11 +54,11 @@ jobs: - name: Install dependencies run: | sudo apt update - sudo apt install -y ninja-build ${{ matrix.deps }} + sudo apt install -y ninja-build if [[ "${{ matrix.compiler }}" == "llvm" ]]; then - sudo apt install -y "clang++-${{ matrix.compiler }}" + sudo apt install -y "clang++-${{ compiler-version }}" elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then - sudo apt install -y "g++-${{ matrix.compiler }}" + sudo apt install -y "g++-${{ compiler-version }}" fi - name: Compile run: | From e13c7cb1c2515aef7763f309b153112a676b5f8e Mon Sep 17 00:00:00 2001 From: BestITUserEUW Date: Sun, 6 Jul 2025 18:17:28 +0200 Subject: [PATCH 5/6] lets try again --- .github/workflows/linux.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index d2b462a..6fe7470 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -56,9 +56,9 @@ jobs: sudo apt update sudo apt install -y ninja-build if [[ "${{ matrix.compiler }}" == "llvm" ]]; then - sudo apt install -y "clang++-${{ compiler-version }}" + sudo apt install -y "clang++-${{ matrix.compiler-version }}" elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then - sudo apt install -y "g++-${{ compiler-version }}" + sudo apt install -y "g++-${{ matrix.compiler-version }}" fi - name: Compile run: | From 9c4a3e2f436ad8a3edbc2a107e247d647da648df Mon Sep 17 00:00:00 2001 From: BestITUserEUW Date: Sun, 6 Jul 2025 18:22:05 +0200 Subject: [PATCH 6/6] go back to only install deps that are not present --- .github/workflows/linux.yaml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 6fe7470..8d38252 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -19,10 +19,12 @@ jobs: cxx: 20 - compiler: llvm compiler-version: 19 + deps: "clang-19" cxx: 23 - compiler: gcc compiler-version: 11 - cxx: 20 + cxx: 20 + deps: "g++-11" - compiler: gcc compiler-version: 12 cxx: 20 @@ -54,12 +56,7 @@ jobs: - name: Install dependencies run: | sudo apt update - sudo apt install -y ninja-build - if [[ "${{ matrix.compiler }}" == "llvm" ]]; then - sudo apt install -y "clang++-${{ matrix.compiler-version }}" - elif [[ "${{ matrix.compiler }}" == "gcc" ]]; then - sudo apt install -y "g++-${{ matrix.compiler-version }}" - fi + sudo apt install -y ninja-build ${{ matrix.deps }} - name: Compile run: | if [[ "${{ matrix.compiler }}" == "llvm" ]]; then