Hyper API for C++  0.0.16638
Hyper client library for C++ applications
Connection.hpp
Go to the documentation of this file.
1 
5 #ifndef TABLEAU_HYPER_CONNECTION_HPP
6 #define TABLEAU_HYPER_CONNECTION_HPP
7 
8 #include <functional>
9 #include <hyperapi/Catalog.hpp>
13 #include <hyperapi/Name.hpp>
14 #include <hyperapi/Result.hpp>
15 #include <hyperapi/impl/infra.hpp>
16 #include <hyperapi/optional.hpp>
17 #include <memory>
18 #include <mutex>
19 #include <new>
20 #include <string>
21 #include <hyperapi/hyperapi.h>
22 
23 namespace hyperapi {
24 
26 enum class CreateMode {
28  None = HYPER_DO_NOT_CREATE,
30  Create = HYPER_CREATE,
32  CreateIfNotExists = HYPER_CREATE_IF_NOT_EXISTS,
34  CreateAndReplace = HYPER_CREATE_AND_REPLACE
35 };
36 
37 class Value;
38 
42 class Connection final {
43  using CatalogPimpl = std::unique_ptr<Catalog>;
44 
45  public:
55  Connection(const Endpoint& endpoint, const std::unordered_map<std::string, std::string>& parameters = {});
56 
68  Connection(
69  const Endpoint& endpoint,
70  const std::string& databasePath,
71  CreateMode createMode = CreateMode::None,
72  const std::unordered_map<std::string, std::string>& parameters = {});
73 
79  Connection() noexcept {}
80 
84  virtual ~Connection() noexcept;
85 
87  Connection(Connection&& other) noexcept;
88 
90  Connection& operator=(Connection&& other) noexcept;
91 
92  Connection(const Connection& other) = delete;
93  Connection& operator=(const Connection& other) = delete;
94 
111  HYPER_API_NODISCARD Result executeQuery(const std::string& sql);
112 
127  int64_t executeCommand(const std::string& sql);
128 
169  template <typename T>
170  T executeScalarQuery(const std::string& sql);
171 
177  Catalog& getCatalog() noexcept;
178 
188  void cancel() noexcept;
189 
203  bool isReady();
204 
208  bool isOpen() const noexcept { return m_handle != nullptr; }
209 
214  virtual void close() noexcept;
215 
224 
231  bool isCapabilityActive(const std::string& capabilityFlag);
232 
241  static std::vector<HyperServiceVersion> querySupportedHyperServiceVersionRange(const Endpoint& endpoint);
242 
243  private:
245  std::mutex m_mutex;
247  hyper_connection_t* m_handle = nullptr;
249  CatalogPimpl m_catalog;
251  std::unique_ptr<internal::NoticeReceiver> noticeReceiver{new internal::NoticeReceiver()};
253  std::unique_ptr<internal::AsyncResultCallback> asyncResultCallback{new internal::AsyncResultCallback()};
254 
255  friend class Catalog;
256  friend class Inserter;
257  friend void internal::setNoticeReceiver(Connection& connection, internal::NoticeReceiver noticeReceiver) noexcept;
258  friend void internal::setAsyncResultCallback(Connection& connection, internal::AsyncResultCallback asyncResultCallback) noexcept;
259  friend const internal::AsyncResultCallback& internal::getAsyncResultCallback(Connection& connection) noexcept;
260  friend hyper_connection_t* internal::getHandle(Connection&) noexcept;
261 };
262 }
263 
264 #include <hyperapi/impl/Catalog.impl.hpp>
265 #include <hyperapi/impl/Connection.impl.hpp>
266 
267 #endif
hyperapi::Connection::executeQuery
HYPER_API_NODISCARD Result executeQuery(const std::string &sql)
Executes a SQL query and returns the result.
hyperapi::CreateMode::Create
Create the database. Method will fail if the database already exists.
hyperapi::CreateMode::CreateAndReplace
Create the database. If it already exists, drop the old one first.
hyperapi::CreateMode
CreateMode
Database creation behavior during connection establishing.
Definition: Connection.hpp:26
hyperapi::Connection::querySupportedHyperServiceVersionRange
static std::vector< HyperServiceVersion > querySupportedHyperServiceVersionRange(const Endpoint &endpoint)
Connects to the Hyper endpoint and determines which Hyper Service version numbers are common between ...
hyperapi::Connection::isOpen
bool isOpen() const noexcept
Checks whether the connection is open.
Definition: Connection.hpp:208
hyperapi::Connection::executeScalarQuery
T executeScalarQuery(const std::string &sql)
Executes a SQL query that returns exactly one row with one column.
HyperServiceVersion.hpp
Result.hpp
hyperapi::Connection::isCapabilityActive
bool isCapabilityActive(const std::string &capabilityFlag)
Returns true if the capability flag is active on this connection.
hyperapi::Connection::~Connection
virtual ~Connection() noexcept
Destructor.
hyperapi::CreateMode::None
Do not create the database. Method will fail if database doesn't exist.
hyperapi::Connection::cancel
void cancel() noexcept
Issues an asynchronous cancel request for the running query on the given connection.
HyperException.hpp
hyperapi::Connection::isReady
bool isReady()
Checks whether the connection is ready, i.e., if the connection can be used.
hyperapi::Result
Base class for a result of a query.
Definition: Result.hpp:325
hyperapi::Catalog
The catalog class gives access to the metadata of the attached databases of a connection.
Definition: Catalog.hpp:31
hyperapi::Connection::getHyperServiceVersion
HyperServiceVersion getHyperServiceVersion()
Returns the Hyper Service version of this connection.
HyperProcess.hpp
hyperapi::Connection
Defines a Hyper connection.
Definition: Connection.hpp:42
hyperapi::Endpoint
Describes a network endpoint at which a Hyper server is accessible.
Definition: Endpoint.hpp:14
hyperapi::Connection::executeCommand
int64_t executeCommand(const std::string &sql)
Executes a SQL command and returns the affected row count, if any.
hyperapi::Connection::Connection
Connection() noexcept
Constructs a Connection object that does not represent a connection.
Definition: Connection.hpp:79
hyperapi
The primary namespace of the Hyper API for C++.
Definition: ByteSpan.hpp:15
hyperapi::Connection::close
virtual void close() noexcept
Closes the connection.
hyperapi::CreateMode::CreateIfNotExists
Create the database if it doesn't exist.
hyperapi::HyperServiceVersion
A Hyper Service version number of the form 'major.minor'.
Definition: HyperServiceVersion.hpp:15
hyperapi::Connection::getCatalog
Catalog & getCatalog() noexcept
Returns the catalog of this connection.
Catalog.hpp
Name.hpp
optional.hpp