1 //
2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 #pragma once
8 
9 #include "td/db/DbKey.h"
10 #include "td/db/SqliteDb.h"
11 
12 #include "td/actor/SchedulerLocalStorage.h"
13 
14 #include "td/utils/common.h"
15 #include "td/utils/optional.h"
16 
17 namespace td {
18 
19 class SqliteConnectionSafe {
20  public:
21   SqliteConnectionSafe() = default;
22   SqliteConnectionSafe(string path, DbKey key, optional<int32> cipher_version = {});
23 
24   SqliteDb &get();
25   void set(SqliteDb &&db);
26 
27   void close();
28 
29   void close_and_destroy();
30 
31  private:
32   string path_;
33   LazySchedulerLocalStorage<SqliteDb> lsls_connection_;
34 };
35 
36 }  // namespace td
37