Hyper API for C++ 0.0.24081
Hyper client library for C++ applications
Loading...
Searching...
No Matches
Connection.hpp
Go to the documentation of this file.
1
5#ifndef TABLEAU_HYPER_CONNECTION_HPP
6#define TABLEAU_HYPER_CONNECTION_HPP
7
9#include <hyperapi/Result.hpp>
10#include <hyperapi/impl/infra.hpp>
11#include <memory>
12#include <mutex>
13#include <string>
14#include <unordered_map>
15#include <hyperapi/hyperapi.h>
16
17namespace hyperapi {
18
20enum class CreateMode {
22 None = HYPER_DO_NOT_CREATE,
24 Create = HYPER_CREATE,
26 CreateIfNotExists = HYPER_CREATE_IF_NOT_EXISTS,
28 CreateAndReplace = HYPER_CREATE_AND_REPLACE
29};
30
31class Value;
32class Endpoint;
36class Connection final {
37 using CatalogPimpl = std::unique_ptr<Catalog>;
38
39 public:
49 Connection(const Endpoint& endpoint, const std::unordered_map<std::string, std::string>& parameters = {});
50
63 const Endpoint& endpoint,
64 const std::string& databasePath,
65 CreateMode createMode = CreateMode::None,
66 const std::unordered_map<std::string, std::string>& parameters = {});
67
73 Connection() noexcept {}
74
78 ~Connection() noexcept;
79
81 Connection(Connection&& other) noexcept;
82
84 Connection& operator=(Connection&& other) noexcept;
85
86 Connection(const Connection& other) = delete;
87 Connection& operator=(const Connection& other) = delete;
88
105 HYPER_API_NODISCARD Result executeQuery(const std::string& sql);
106
121 int64_t executeCommand(const std::string& sql);
122
163 template <typename T>
164 T executeScalarQuery(const std::string& sql);
165
171 Catalog& getCatalog() noexcept;
172
182 void cancel() noexcept;
183
197 bool isReady();
198
202 bool isOpen() const noexcept { return handle_ != nullptr; }
203
208 void close() noexcept;
209
210 private:
212 std::mutex mutex_;
214 hyper_connection_t* handle_ = nullptr;
216 CatalogPimpl catalog_;
218 std::unique_ptr<internal::NoticeReceiver> noticeReceiver_{new internal::NoticeReceiver()};
220 std::unique_ptr<internal::AsyncResultCallback> asyncResultCallback_{new internal::AsyncResultCallback()};
221
222 friend class Catalog;
223 friend class Inserter;
224 friend void internal::setNoticeReceiver(Connection& connection, internal::NoticeReceiver noticeReceiver) noexcept;
225 friend void internal::setAsyncResultCallback(Connection& connection, internal::AsyncResultCallback asyncResultCallback) noexcept;
226 friend const internal::AsyncResultCallback& internal::getAsyncResultCallback(Connection& connection) noexcept;
227 friend hyper_connection_t* internal::getHandle(Connection&) noexcept;
228};
229}
230
231#include <hyperapi/impl/Catalog.impl.hpp> // IWYU pragma: export
232#include <hyperapi/impl/Connection.impl.hpp> // IWYU pragma: export
233
234#endif
The catalog class gives access to the metadata of the attached databases of a connection.
Definition Catalog.hpp:29
Defines a Hyper connection.
void cancel() noexcept
Issues an asynchronous cancel request for the running query on the given connection.
~Connection() noexcept
Destructor.
void close() noexcept
Closes the connection.
Catalog & getCatalog() noexcept
Returns the catalog of this connection.
bool isOpen() const noexcept
Checks whether the connection is open.
Connection(const Endpoint &endpoint, const std::unordered_map< std::string, std::string > &parameters={})
Connects to a Hyper endpoint without attaching to a database.
HYPER_API_NODISCARD Result executeQuery(const std::string &sql)
Executes a SQL query and returns the result.
bool isReady()
Checks whether the connection is ready, i.e., if the connection can be used.
Connection() noexcept
Constructs a Connection object that does not represent a connection.
int64_t executeCommand(const std::string &sql)
Executes a SQL command and returns the affected row count, if any.
Connection(const Endpoint &endpoint, const std::string &databasePath, CreateMode createMode=CreateMode::None, const std::unordered_map< std::string, std::string > &parameters={})
Connects to a Hyper endpoint and attaches to exactly one database.
T executeScalarQuery(const std::string &sql)
Executes a SQL query that returns exactly one row with one column.
Describes a network endpoint at which a Hyper server is accessible.
Definition Endpoint.hpp:14
Base class for a result of a query.
Definition Result.hpp:319
The primary namespace of the Hyper API for C++.
Definition ByteSpan.hpp:14
CreateMode
Database creation behavior during connection establishing.
@ CreateIfNotExists
Create the database if it doesn't exist.
@ Create
Create the database. Method will fail if the database already exists.
@ None
Do not create the database. Method will fail if database doesn't exist.
@ CreateAndReplace
Create the database. If it already exists, drop the old one first.