Procházet zdrojové kódy

Re-inserting a package into the catalog will replace it

default_compile_flags
vector-of-bool před 5 roky
rodič
revize
e2c1b6d6bb
3 změnil soubory, kde provedl 36 přidání a 11 odebrání
  1. +16
    -6
      src/dds/catalog/catalog.cpp
  2. +1
    -0
      src/dds/catalog/catalog.hpp
  3. +19
    -5
      src/dds/catalog/catalog.test.cpp

+ 16
- 6
src/dds/catalog/catalog.cpp Zobrazit soubor

@@ -113,7 +113,7 @@ void catalog::_store_pkg(const package_info& pkg, const git_remote_listing& git)
sqlite3::exec( //
_stmt_cache,
R"(
INSERT INTO dds_cat_pkgs (
INSERT OR REPLACE INTO dds_cat_pkgs (
name,
version,
git_url,
@@ -216,6 +216,19 @@ std::optional<package_info> catalog::get(const package_id& pk_id) const noexcept
};
}

auto pair_to_pkg_id = [](auto&& pair) {
const auto& [name, ver] = pair;
return package_id{name, semver::version::parse(ver)};
};

std::vector<package_id> catalog::all() const noexcept {
return sqlite3::exec_iter<std::string, std::string>( //
_stmt_cache,
"SELECT name, version FROM dds_cat_pkgs"_sql)
| ranges::views::transform(pair_to_pkg_id) //
| ranges::to_vector;
}

std::vector<package_id> catalog::by_name(std::string_view sv) const noexcept {
return sqlite3::exec_iter<std::string, std::string>( //
_stmt_cache,
@@ -224,11 +237,8 @@ std::vector<package_id> catalog::by_name(std::string_view sv) const noexcept {
FROM dds_cat_pkgs
WHERE name = ?
)"_sql,
std::tie(sv)) //
| ranges::views::transform([](auto& pair) {
auto& [name, ver] = pair;
return package_id{name, semver::version::parse(ver)};
})
std::tie(sv)) //
| ranges::views::transform(pair_to_pkg_id) //
| ranges::to_vector;
}


+ 1
- 0
src/dds/catalog/catalog.hpp Zobrazit soubor

@@ -41,6 +41,7 @@ public:
void store(const package_info& info);
std::optional<package_info> get(const package_id& id) const noexcept;

std::vector<package_id> all() const noexcept;
std::vector<package_id> by_name(std::string_view sv) const noexcept;
std::vector<dependency> dependencies_of(const package_id& pkg) const noexcept;


+ 19
- 5
src/dds/catalog/catalog.test.cpp Zobrazit soubor

@@ -20,14 +20,28 @@ TEST_CASE_METHOD(catalog_test_case, "Store a simple package") {
{},
dds::git_remote_listing{"http://example.com", "master", std::nullopt},
});
CHECK_THROWS(db.store(dds::package_info{
dds::package_id("foo", semver::version::parse("1.2.3")),
{},
dds::git_remote_listing{"http://example.com", "master", std::nullopt},
}));

auto pkgs = db.by_name("foo");
REQUIRE(pkgs.size() == 1);
CHECK(pkgs[0].name == "foo");
CHECK(pkgs[0].version == semver::version::parse("1.2.3"));
auto info = db.get(pkgs[0]);
REQUIRE(info);
CHECK(info->ident == pkgs[0]);
CHECK(info->deps.empty());
CHECK(std::holds_alternative<dds::git_remote_listing>(info->remote));
CHECK(std::get<dds::git_remote_listing>(info->remote).ref == "master");

// Update the entry with a new git remote ref
CHECK_NOTHROW(db.store(dds::package_info{
dds::package_id("foo", semver::version::parse("1.2.3")),
{},
dds::git_remote_listing{"http://example.com", "develop", std::nullopt},
}));
// The previous pkg_id is still a valid lookup key
info = db.get(pkgs[0]);
REQUIRE(info);
CHECK(std::get<dds::git_remote_listing>(info->remote).ref == "develop");
}

TEST_CASE_METHOD(catalog_test_case, "Package requirements") {

Načítá se…
Zrušit
Uložit