summaryrefslogtreecommitdiff
path: root/libs/tdlib/td/tddb/td/db/SqliteKeyValueSafe.h
blob: d63af3cfb2437f45037bd13c600cca7ae8230028 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// 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

#include "td/db/SqliteConnectionSafe.h"
#include "td/db/SqliteKeyValue.h"

#include <memory>

namespace td {

class SqliteKeyValueSafe {
 public:
  SqliteKeyValueSafe(string name, std::shared_ptr<SqliteConnectionSafe> safe_connection)
      : lsls_kv_([name = std::move(name), safe_connection = std::move(safe_connection)] {
        SqliteKeyValue kv;
        kv.init_with_connection(safe_connection->get().clone(), name).ensure();
        return kv;
      }) {
  }
  SqliteKeyValue &get() {
    return lsls_kv_.get();
  }
  void close() {
    lsls_kv_.clear_values();
  }

 private:
  LazySchedulerLocalStorage<SqliteKeyValue> lsls_kv_;
};

}  // namespace td