userver: userver/storages/sqlite/infra/connection_ptr.hpp Source File
Loading...
Searching...
No Matches
connection_ptr.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/sqlite/infra/connection_ptr.hpp
4/// @brief @copybrief storages::sqlite::infra::ConnectionPtr
5
6#include <memory>
7
8#include <userver/storages/sqlite/sqlite_fwd.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace storages::sqlite::infra {
13
14/// @brief Owns a SQLite connection and keeps its parent pool alive
16public:
17 ConnectionPtr(std::shared_ptr<Pool>&& pool, std::unique_ptr<impl::Connection>&& connection);
18 ~ConnectionPtr();
19
20 ConnectionPtr(ConnectionPtr&&) noexcept;
21 ConnectionPtr& operator=(ConnectionPtr&&) noexcept;
22
23 bool IsValid() const noexcept;
24 impl::Connection* get() const noexcept;
25
26 impl::Connection& operator*() const;
27 impl::Connection* operator->() const noexcept;
28
29private:
30 void Reset(std::unique_ptr<impl::Connection> conn, std::shared_ptr<Pool> pool);
31 void Release();
32
33 std::shared_ptr<Pool> pool_;
34 std::unique_ptr<impl::Connection> conn_;
35};
36
37} // namespace storages::sqlite::infra
38
39USERVER_NAMESPACE_END