userver: userver/storages/postgres/database.hpp Source File
Loading...
Searching...
No Matches
database.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/postgres/database.hpp
4/// @brief @copybrief storages::postgres::Database
5
6#include <vector>
7
8#include <userver/storages/postgres/database_fwd.hpp>
9#include <userver/storages/postgres/dsn.hpp>
10#include <userver/storages/postgres/options.hpp>
11#include <userver/storages/postgres/postgres_fwd.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace components {
16
17class Postgres;
18
19} // namespace components
20
21namespace storages::postgres {
22
23/// Object for accessing PostgreSQL database instance (sharded or not)
24class Database {
25public:
26 /// Cluster accessor for default shard number
27 ClusterPtr GetCluster() const;
28
29 /// Cluster accessor for specific shard number
30 ClusterPtr GetClusterForShard(size_t shard) const;
31
32 /// Get total shard count
33 size_t GetShardCount() const { return clusters_.size(); }
34
35 void UpdateClusterDescription(const std::vector<DsnList>&);
36
37private:
38 friend class components::Postgres;
39 std::vector<storages::postgres::ClusterPtr> clusters_;
40};
41
42} // namespace storages::postgres
43
44USERVER_NAMESPACE_END