Sqlite: add a scoped per-call busy-timeout override (VL-SQLITE-04)
This commit is contained in:
1 parent
797ea630a1
commit
7e5cf7379a
3 files changed
+159
No files matched your search
@@ -242,6 +242,40 @@ namespace Void::Sqlite
|
||||
bool m_active{false};
|
||||
};
|
||||
|
||||
/// Scoped per-call override of the connection busy timeout.
|
||||
///
|
||||
/// The previous timeout is restored when this object is destroyed (or
|
||||
/// explicitly via restore()), so a single statement or transaction can use
|
||||
/// a tighter or looser bound without permanently changing the connection.
|
||||
class BusyTimeoutOverride
|
||||
{
|
||||
public:
|
||||
BusyTimeoutOverride() noexcept = default;
|
||||
~BusyTimeoutOverride();
|
||||
BusyTimeoutOverride(BusyTimeoutOverride&&) noexcept;
|
||||
BusyTimeoutOverride& operator=(BusyTimeoutOverride&&) noexcept;
|
||||
BusyTimeoutOverride(const BusyTimeoutOverride&) = delete;
|
||||
BusyTimeoutOverride& operator=(const BusyTimeoutOverride&) = delete;
|
||||
|
||||
[[nodiscard]] bool is_active() const noexcept { return m_active; }
|
||||
[[nodiscard]] std::chrono::milliseconds previous() const noexcept
|
||||
{
|
||||
return m_previous;
|
||||
}
|
||||
|
||||
/// Restore the previous timeout early. Idempotent.
|
||||
void restore() noexcept;
|
||||
|
||||
private:
|
||||
friend class Database;
|
||||
BusyTimeoutOverride(std::shared_ptr<detail::ConnectionState> conn,
|
||||
std::chrono::milliseconds previous) noexcept;
|
||||
|
||||
std::shared_ptr<detail::ConnectionState> m_conn{};
|
||||
std::chrono::milliseconds m_previous{0};
|
||||
bool m_active{false};
|
||||
};
|
||||
|
||||
/// A single forward schema migration applied when the database's
|
||||
/// user_version is below `version`.
|
||||
struct Migration {
|
||||
@@ -300,6 +334,12 @@ namespace Void::Sqlite
|
||||
std::size_t max_rows = 0,
|
||||
std::size_t max_bytes = 0);
|
||||
|
||||
/// Temporarily override the connection busy timeout for the next
|
||||
/// calls. The previous value is restored when the returned scope is
|
||||
/// destroyed. A negative timeout is rejected.
|
||||
[[nodiscard]] Result<BusyTimeoutOverride>
|
||||
override_busy_timeout(std::chrono::milliseconds timeout);
|
||||
|
||||
/// Explicitly close the connection. Stops admission and returns
|
||||
/// SqliteErrorCode::busy while live statements/transactions/savepoints
|
||||
/// remain open.
|
||||
|
||||
Reference in new issue
Block a user