userver: userver/storages/postgres/portal.hpp Source File
Loading...
Searching...
No Matches
portal.hpp
1#pragma once
2
3#include <memory>
4#include <string>
5
6#include <userver/engine/deadline.hpp>
7
8#include <userver/storages/postgres/detail/connection_ptr.hpp>
9#include <userver/storages/postgres/detail/query_parameters.hpp>
10#include <userver/storages/postgres/options.hpp>
11#include <userver/storages/postgres/postgres_fwd.hpp>
12#include <userver/storages/postgres/query.hpp>
13#include <userver/storages/postgres/result_set.hpp>
14
15#include <userver/utils/fast_pimpl.hpp>
16#include <userver/utils/strong_typedef.hpp>
17
18USERVER_NAMESPACE_BEGIN
19
20namespace storages::postgres {
21
22using PortalName = USERVER_NAMESPACE::utils::StrongTypedef<struct PortalNameTag, std::string>;
23
24class Portal {
25public:
26 Portal(
27 detail::Connection* conn,
28 const Query& query,
29 const detail::QueryParameters& = {},
30 OptionalCommandControl cmd_ctl = {}
31 );
32 Portal(
33 detail::Connection* conn,
34 const PortalName&,
35 const Query& query,
36 const detail::QueryParameters& = {},
37 OptionalCommandControl cmd_ctl = {}
38 );
39
40 Portal(Portal&&) noexcept;
41 Portal& operator=(Portal&&) noexcept;
42
43 Portal(const Portal&) = delete;
44 Portal& operator=(const Portal&) = delete;
45
46 ~Portal();
47
48 ResultSet Fetch(std::uint32_t n_rows);
49
50 bool Done() const;
51 std::size_t FetchedSoFar() const;
52
53 explicit operator bool() const { return !Done(); }
54
55 /// Returns true if CMake option USERVER_FEATURE_PATCH_LIBPQ was set to ON
56 /// and PostgreSQL portals could be created.
57 static bool IsSupportedByDriver() noexcept;
58
59private:
60 static constexpr std::size_t kImplSize = 88;
61 static constexpr std::size_t kImplAlign = 8;
62
63 struct Impl;
64 USERVER_NAMESPACE::utils::FastPimpl<Impl, kImplSize, kImplAlign> pimpl_;
65};
66
67} // namespace storages::postgres
68
69USERVER_NAMESPACE_END