5#include "../SqlSchema.hpp"
6#include "../SqlServerType.hpp"
18namespace Lightweight::SqlBackup::detail
22enum class ChunkStrategy : uint8_t
32struct TableBackupState
35 std::atomic<size_t> remainingChunks { 0 };
37 std::atomic<size_t> processedRows { 0 };
39 std::atomic<bool> started {
false };
41 std::atomic<bool> failed {
false };
43 std::atomic<size_t> totalRows { 0 };
52 SqlSchema::Table
const* table =
nullptr;
54 ChunkStrategy strategy = ChunkStrategy::Offset;
58 uint32_t windowIndex = 0;
76 bool arrayFetchable =
false;
79 TableBackupState* state =
nullptr;
84using PkBoundsFunction =
85 std::function<std::optional<std::pair<int64_t, int64_t>>(SqlSchema::Table
const& table, std::string
const& pkColumn)>;
92 std::vector<Chunk> chunks;
95 std::deque<TableBackupState> tableStates;
97 std::vector<SqlSchema::Table const*> emptyTables;
112[[nodiscard]] LIGHTWEIGHT_API ChunkPlan PlanChunks(std::vector<SqlSchema::Table>
const& tables,
114 PkBoundsFunction
const& pkBounds,
115 SqlServerType serverType);
120[[nodiscard]] LIGHTWEIGHT_API
bool TableHasLobColumn(SqlSchema::Table
const& table);
153[[nodiscard]] LIGHTWEIGHT_API
bool TableIsArrayFetchable(SqlSchema::Table
const& table, SqlServerType serverType);
157[[nodiscard]] LIGHTWEIGHT_API std::optional<std::string> SingleNumericPrimaryKey(SqlSchema::Table
const& table);
168[[nodiscard]] LIGHTWEIGHT_API std::vector<std::pair<int64_t, int64_t>> PlanPrimaryKeyWindows(int64_t pkMin,
170 int64_t rowsPerChunk);
175constexpr int64_t MaxWindowsPerTable = 1024;
187[[nodiscard]] LIGHTWEIGHT_API int64_t CappedWindowWidth(int64_t pkMin,
189 int64_t rowsPerChunk,
190 int64_t maxWindowsPerTable);