23
23
#include < tao/pq/internal/poll.hpp>
24
24
#include < tao/pq/internal/zsv.hpp>
25
25
#include < tao/pq/isolation_level.hpp>
26
+ #include < tao/pq/log.hpp>
26
27
#include < tao/pq/notification.hpp>
27
28
#include < tao/pq/parameter.hpp>
28
29
#include < tao/pq/pipeline_status.hpp>
@@ -66,6 +67,7 @@ namespace tao::pq
66
67
std::function< poll::callback > m_poll;
67
68
std::function< void ( const notification& ) > m_notification_handler;
68
69
std::map< std::string, std::function< void ( const char * ) >, std::less<> > m_notification_handlers;
70
+ std::shared_ptr< log > m_log;
69
71
70
72
[[nodiscard]] auto escape_identifier ( const std::string_view identifier ) const -> std::unique_ptr< char, decltype( &PQfreemem ) >;
71
73
@@ -122,19 +124,57 @@ namespace tao::pq
122
124
123
125
[[nodiscard]] auto error_message () const -> const char*;
124
126
125
- [[nodiscard]] auto poll_callback () const noexcept -> const std::function< poll::callback >&;
126
- void set_poll_callback ( std::function< poll::callback > poll_cb ) noexcept ;
127
- void reset_poll_callback ();
127
+ [[nodiscard]] auto poll_callback () const noexcept -> decltype( auto )
128
+ {
129
+ return m_poll;
130
+ }
131
+
132
+ void set_poll_callback ( std::function< poll::callback > poll_cb ) noexcept
133
+ {
134
+ m_poll = std::move ( poll_cb );
135
+ }
136
+
137
+ void reset_poll_callback ()
138
+ {
139
+ m_poll = internal::poll;
140
+ }
141
+
142
+ [[nodiscard]] auto notification_handler () const noexcept -> decltype( auto )
143
+ {
144
+ return m_notification_handler;
145
+ }
146
+
147
+ void set_notification_handler ( std::function< void ( const notification& ) > handler ) noexcept
148
+ {
149
+ m_notification_handler = std::move ( handler );
150
+ }
151
+
152
+ void reset_notification_handler () noexcept
153
+ {
154
+ m_notification_handler = nullptr ;
155
+ }
128
156
129
- [[nodiscard]] auto notification_handler () const -> std::function< void( const notification& ) >;
130
157
[[nodiscard]] auto notification_handler ( const std::string_view channel ) const -> std::function< void( const char * payload ) >;
131
158
132
- void set_notification_handler ( const std::function< void ( const notification& ) >& handler );
133
159
void set_notification_handler ( const std::string_view channel, const std::function< void ( const char * payload ) >& handler );
134
160
135
- void reset_notification_handler () noexcept ;
136
161
void reset_notification_handler ( const std::string_view channel ) noexcept ;
137
162
163
+ [[nodiscard]] auto log_handler () const noexcept -> decltype( auto )
164
+ {
165
+ return m_log;
166
+ }
167
+
168
+ void set_log_handler ( const std::shared_ptr< pq::log >& log ) noexcept
169
+ {
170
+ m_log = log ;
171
+ }
172
+
173
+ void reset_log_handler () noexcept
174
+ {
175
+ m_log = nullptr ;
176
+ }
177
+
138
178
[[nodiscard]] auto status () const noexcept -> connection_status;
139
179
[[nodiscard]] auto transaction_status () const noexcept -> pq::transaction_status;
140
180
@@ -156,6 +196,8 @@ namespace tao::pq
156
196
157
197
[[nodiscard]] auto is_busy () const noexcept -> bool;
158
198
199
+ [[nodiscard]] auto flush () -> bool;
200
+
159
201
[[nodiscard]] auto direct () -> std::shared_ptr< pq::transaction >;
160
202
161
203
[[nodiscard]] auto transaction () -> std::shared_ptr< pq::transaction >;
@@ -190,8 +232,15 @@ namespace tao::pq
190
232
return m_timeout;
191
233
}
192
234
193
- void set_timeout ( const std::chrono::milliseconds timeout );
194
- void reset_timeout () noexcept ;
235
+ void set_timeout ( const std::chrono::milliseconds timeout ) noexcept
236
+ {
237
+ m_timeout = timeout;
238
+ }
239
+
240
+ void reset_timeout () noexcept
241
+ {
242
+ m_timeout = std::nullopt;
243
+ }
195
244
196
245
[[nodiscard]] auto password ( const internal::zsv passwd, const internal::zsv user, const internal::zsv algorithm = " scram-sha-256" ) -> std::string;
197
246
0 commit comments