2018-12-31 20:04:05 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2019-10-03 19:15:15 +02:00
|
|
|
#include "td/db/DbKey.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/db/SqliteDb.h"
|
|
|
|
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/actor/SchedulerLocalStorage.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/common.h"
|
2020-08-14 16:48:43 +02:00
|
|
|
#include "td/utils/optional.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-08-18 21:04:20 +02:00
|
|
|
#include <atomic>
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class SqliteConnectionSafe {
|
|
|
|
public:
|
|
|
|
SqliteConnectionSafe() = default;
|
2021-09-22 16:20:10 +02:00
|
|
|
SqliteConnectionSafe(string path, DbKey key, optional<int32> cipher_version = {});
|
2019-10-03 19:15:15 +02:00
|
|
|
|
|
|
|
SqliteDb &get();
|
2020-08-14 16:11:58 +02:00
|
|
|
void set(SqliteDb &&db);
|
2019-10-03 19:15:15 +02:00
|
|
|
|
|
|
|
void close();
|
|
|
|
|
|
|
|
void close_and_destroy();
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
2019-10-03 19:38:47 +02:00
|
|
|
string path_;
|
2022-08-18 22:31:14 +02:00
|
|
|
std::atomic<uint32> close_state_{0};
|
2019-10-03 19:15:15 +02:00
|
|
|
LazySchedulerLocalStorage<SqliteDb> lsls_connection_;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|