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 =
23 USERVER_NAMESPACE::utils::StrongTypedef<struct PortalNameTag, std::string>;
24
25class Portal {
26 public:
27 Portal(detail::Connection* conn, const Query& query,
28 const detail::QueryParameters& = {},
29 OptionalCommandControl cmd_ctl = {});
30 Portal(detail::Connection* conn, const PortalName&, const Query& query,
31 const detail::QueryParameters& = {},
32 OptionalCommandControl cmd_ctl = {});
33
34 Portal(Portal&&) noexcept;
35 Portal& operator=(Portal&&) noexcept;
36
37 Portal(const Portal&) = delete;
38 Portal& operator=(const Portal&) = delete;
39
40 ~Portal();
41
42 ResultSet Fetch(std::uint32_t n_rows);
43
44 bool Done() const;
45 std::size_t FetchedSoFar() const;
46
47 explicit operator bool() const { return !Done(); }
48
49 /// Returns true if CMake option USERVER_FEATURE_PATCH_LIBPQ was set to ON
50 /// and PostgreSQL portals could be created.
51 static bool IsSupportedByDriver() noexcept;
52
53 private:
54 static constexpr std::size_t kImplSize = 88;
55 static constexpr std::size_t kImplAlign = 8;
56
57 struct Impl;
58 USERVER_NAMESPACE::utils::FastPimpl<Impl, kImplSize, kImplAlign> pimpl_;
59};
60
61} // namespace storages::postgres
62
63USERVER_NAMESPACE_END