Selaa lähdekoodia

Rename to `catalog` to avoid confusion

default_compile_flags
vector-of-bool 5 vuotta sitten
vanhempi
commit
6de88d9845
3 muutettua tiedostoa jossa 23 lisäystä ja 23 poistoa
  1. +9
    -9
      src/dds/repo/catalog.cpp
  2. +7
    -7
      src/dds/repo/catalog.hpp
  3. +7
    -7
      src/dds/repo/catalog.test.cpp

src/dds/repo/repodb.cpp → src/dds/repo/catalog.cpp Näytä tiedosto

@@ -1,4 +1,4 @@
#include "./repodb.hpp"
#include "./catalog.hpp"

#include <neo/sqlite3/exec.hpp>
#include <neo/sqlite3/iter_tuples.hpp>
@@ -88,7 +88,7 @@ void ensure_migrated(sqlite3::database& db) {

} // namespace

repo_database repo_database::open(const std::string& db_path) {
catalog catalog::open(const std::string& db_path) {
auto db = sqlite3::database::open(db_path);
try {
ensure_migrated(db);
@@ -99,13 +99,13 @@ repo_database repo_database::open(const std::string& db_path) {
e.what());
throw;
}
return repo_database(std::move(db));
return catalog(std::move(db));
}

repo_database::repo_database(sqlite3::database db)
catalog::catalog(sqlite3::database db)
: _db(std::move(db)) {}

void repo_database::_store_pkg(const package_info& pkg, const git_remote_listing& git) {
void catalog::_store_pkg(const package_info& pkg, const git_remote_listing& git) {
auto lm_usage = git.auto_lib.value_or(lm::usage{});
sqlite3::exec( //
_stmt_cache,
@@ -135,7 +135,7 @@ void repo_database::_store_pkg(const package_info& pkg, const git_remote_listing
lm_usage.namespace_));
}

void repo_database::store(const package_info& pkg) {
void catalog::store(const package_info& pkg) {
sqlite3::transaction_guard tr{_db};

std::visit([&](auto&& remote) { _store_pkg(pkg, remote); }, pkg.remote);
@@ -164,7 +164,7 @@ void repo_database::store(const package_info& pkg) {
}
}

std::vector<package_id> repo_database::by_name(std::string_view sv) const noexcept {
std::vector<package_id> catalog::by_name(std::string_view sv) const noexcept {
return sqlite3::exec_iter<std::string, std::string>( //
_stmt_cache,
R"(
@@ -180,7 +180,7 @@ std::vector<package_id> repo_database::by_name(std::string_view sv) const noexce
| ranges::to_vector;
}

std::vector<dependency> repo_database::dependencies_of(const package_id& pkg) const noexcept {
std::vector<dependency> catalog::dependencies_of(const package_id& pkg) const noexcept {
return sqlite3::exec_iter<std::string,
std::string>( //
_stmt_cache,
@@ -213,7 +213,7 @@ void check_json(bool b, std::string_view what) {

} // namespace

void repo_database::import_json_str(std::string_view content) {
void catalog::import_json_str(std::string_view content) {
using nlohmann::json;

auto root = json::parse(content);

src/dds/repo/repodb.hpp → src/dds/repo/catalog.hpp Näytä tiedosto

@@ -21,21 +21,21 @@ struct package_info {
std::variant<git_remote_listing> remote;
};

class repo_database {
class catalog {
neo::sqlite3::database _db;
mutable neo::sqlite3::statement_cache _stmt_cache{_db};

explicit repo_database(neo::sqlite3::database db);
repo_database(const repo_database&) = delete;
explicit catalog(neo::sqlite3::database db);
catalog(const catalog&) = delete;

void _store_pkg(const package_info&, const git_remote_listing&);

public:
repo_database(repo_database&&) = default;
repo_database& operator=(repo_database&&) = default;
catalog(catalog&&) = default;
catalog& operator=(catalog&&) = default;

static repo_database open(const std::string& db_path);
static repo_database open(path_ref db_path) { return open(db_path.string()); }
static catalog open(const std::string& db_path);
static catalog open(path_ref db_path) { return open(db_path.string()); }

void store(const package_info& info);


src/dds/repo/repodb.test.cpp → src/dds/repo/catalog.test.cpp Näytä tiedosto

@@ -1,4 +1,4 @@
#include <dds/repo/repodb.hpp>
#include <dds/repo/catalog.hpp>

#include <catch2/catch.hpp>

@@ -6,15 +6,15 @@ using namespace std::literals;

TEST_CASE("Create a simple database") {
// Just create and run migrations on an in-memory database
auto repo = dds::repo_database::open(":memory:"s);
auto repo = dds::catalog::open(":memory:"s);
}

class repo_test_case {
class catalog_test_case {
public:
dds::repo_database db = dds::repo_database::open(":memory:"s);
dds::catalog db = dds::catalog::open(":memory:"s);
};

TEST_CASE_METHOD(repo_test_case, "Store a simple package") {
TEST_CASE_METHOD(catalog_test_case, "Store a simple package") {
db.store(dds::package_info{
dds::package_id("foo", semver::version::parse("1.2.3")),
{},
@@ -30,7 +30,7 @@ TEST_CASE_METHOD(repo_test_case, "Store a simple package") {
REQUIRE(pkgs.size() == 1);
}

TEST_CASE_METHOD(repo_test_case, "Package requirements") {
TEST_CASE_METHOD(catalog_test_case, "Package requirements") {
db.store(dds::package_info{
dds::package_id{"foo", semver::version::parse("1.2.3")},
{
@@ -48,7 +48,7 @@ TEST_CASE_METHOD(repo_test_case, "Package requirements") {
CHECK(deps[1].name == "baz");
}

TEST_CASE_METHOD(repo_test_case, "Parse JSON repo") {
TEST_CASE_METHOD(catalog_test_case, "Parse JSON repo") {
db.import_json_str(R"({
"version": 1,
"packages": {

Loading…
Peruuta
Tallenna