From a84be46d879ad3bde0e4a0890ef1108bf5e10b0b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 23 Aug 2025 17:52:28 +0100 Subject: Return count of entities passed to the database --- src/ingestor.cpp | 17 ++++++++++------- src/ingestor.hpp | 10 ++++++---- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ingestor.cpp b/src/ingestor.cpp index c1206a2..e316e84 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -101,37 +101,40 @@ namespace WebStat { } template - void + size_t Ingestor::storeEntities(const std::tuple & values) const { - std::apply( + return std::apply( [this](auto &&... value) { - (this->storeEntity(value), ...); + return (this->storeEntity(value) + ...); }, values); } template - void + size_t Ingestor::storeEntity(const T &) const { + return 0; } - void + size_t Ingestor::storeEntity(const Entity entity) const { auto insert = dbconn->modify(SQL::ENTITY_INSERT, SQL::ENTITY_INSERT_OPTS); insert->bindParamI(0, entity.first); insert->bindParamS(1, entity.second); insert->execute(); + return 1; } - void + size_t Ingestor::storeEntity(const std::optional entity) const { if (entity) { - storeEntity(*entity); + return storeEntity(*entity); } + return 0; } template diff --git a/src/ingestor.hpp b/src/ingestor.hpp index 07a9a7d..53ba81f 100644 --- a/src/ingestor.hpp +++ b/src/ingestor.hpp @@ -24,9 +24,11 @@ namespace WebStat { void ingestLog(std::FILE *); void ingestLogLine(std::string_view); - template void storeEntity(const T &) const; - void storeEntity(Entity) const; - void storeEntity(std::optional) const; + template [[nodiscard]] size_t storeEntity(const T &) const; + // NOLINTNEXTLINE(modernize-use-nodiscard); testing exposition only + size_t storeEntity(Entity) const; + // NOLINTNEXTLINE(modernize-use-nodiscard); testing exposition only + size_t storeEntity(std::optional) const; template void storeLogLine(const std::tuple &) const; protected: @@ -35,7 +37,7 @@ namespace WebStat { size_t linesDiscarded = 0; private: - template void storeEntities(const std::tuple &) const; + template size_t storeEntities(const std::tuple &) const; uint32_t hostnameId; DB::ConnectionPtr dbconn; -- cgit v1.2.3