#pragma once // Read/write access to the `segments` table — the per-connection detail behind // TaskDetail.segmentDetail (download.get) and the segment-bars widget. Written from an // engine progress tick (Scheduler::progress_snapshot); read back on download.get. #include #include #include #include #include "store/sqlite.hpp" #include "velox_proto.hpp" namespace velox::daemon::store { // One segment's live counters, as read off vdm::task::SegmentProgress. `state` is a wire // SegmentState spelling ("pending"/"connecting"/.../"failed") — the caller maps the // engine's own enum, this module stays generic like the others. struct SegmentSnapshot { std::uint32_t index; std::int64_t start_byte; std::int64_t end_byte; // inclusive (ADR 0010) std::int64_t completed_bytes; std::int64_t speed_bps; std::string state; }; class Segments { public: explicit Segments(Db& db) : db_(db) {} // Replaces every row for `task_id` with `segs` in one transaction. Simpler than a // per-index upsert and cheap at <=32 rows, <=4 Hz. DbResult replace_all(std::string_view task_id, const std::vector& segs); // In index order. Empty if the task has never been segmented (TaskDetail's own // description permits this). DbResult> list(std::string_view task_id); private: Db& db_; }; } // namespace velox::daemon::store