Skip to content

add code for the C++Now “postgres” presentation#61

Merged
dietmarkuehl merged 7 commits into
mainfrom
postgres
May 11, 2026
Merged

add code for the C++Now “postgres” presentation#61
dietmarkuehl merged 7 commits into
mainfrom
postgres

Conversation

@dietmarkuehl

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings May 11, 2026 13:13
@dietmarkuehl dietmarkuehl requested a review from camio as a code owner May 11, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds/updates PostgreSQL-related example programs intended to support a C++Now “postgres” talk, including demo code for async libpq usage integrated with beman::execution / beman::net.

Changes:

  • Reworks examples/postgres.cpp into a more elaborate demo (connection limiting, polling/flush loops, multiple concurrent requests).
  • Updates examples/postgres-talk.cpp with additional talk/demo code (mutex/serialization wrapper, multiple queries).
  • Adjusts example build configuration and fixes a file header comment.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

File Description
examples/postgres.cpp New async libpq query flow + connection limiting + demo “timer / two requests” orchestration.
examples/postgres-talk.cpp Talk-focused variant of the postgres demo with a mutex-like wrapper and two query flows.
examples/populate-postgres.cpp Corrects the file header comment to match the filename.
examples/CMakeLists.txt Changes which examples are built/iterated, including postgres-related targets.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/postgres.cpp
Comment on lines 4 to +8
#include <beman/net/net.hpp>
#include <beman/net/detail/repeat_effect_until.hpp>
#include <beman/execution/execution.hpp>
#include <libpq-fe.h>
#include "demo_algorithm.hpp"
Comment thread examples/postgres.cpp
Comment on lines +51 to +54
std::unique_ptr<PGconn, decltype([](auto c) { PQfinish(c); })> conn;
net::ip::tcp::socket socket;
connection(net::io_context& io, PGconn* c)
: conn(c ? c : throw std::runtime_error("connection failed")),
Comment thread examples/postgres.cpp
res.push_back(pg::result(PQgetResult(conn)));
}),
[&res]() noexcept { return !res.empty() && !res.back(); }) |
ex::then([&res] noexcept { return std::move(res); });
Comment thread examples/postgres.cpp
[&conn] noexcept { return !PQisBusy(conn); });
}
auto exec1(pg::connection& conn, const char* query) {
return ex::just() | ex::then([&conn, query] noexcept { PQsendQuery(conn, query); }) |
Comment thread examples/postgres.cpp
Comment on lines +169 to +172
return net::repeat_effect_until(net::async_poll(conn.socket, net::event_type::in) |
ex::upon_error([](auto&&) noexcept {}) |
ex::then([&conn](auto&&...) noexcept { PQconsumeInput(conn); }),
[&conn] noexcept { return !PQisBusy(conn); });
Comment on lines +53 to +57
struct conn {
std::unique_ptr<PGconn, decltype([](auto c) { PQfinish(c); })> cn;
net::ip::tcp::socket socket;
connection(net::io_context& io, PGconn* c)
: conn(c ? c : throw std::runtime_error("connection failed")),
socket(io, io.make_socket(PQsocket(conn.get()))) {}
operator PGconn*() const { return conn.get(); }
conn(net::io_context& io, PGconn* c) : cn(c), socket(io, io.make_socket(PQsocket(c))) {}
operator PGconn*() const { return cn.get(); }
Comment on lines 10 to +14
#include <iostream>
#include <optional>
#include <ranges>
#include <string>
#include <thread>
Comment thread examples/CMakeLists.txt Outdated
Comment on lines 40 to 43
set(xEXAMPLES taps)
set(xEXAMPLES memory-stream)
set(xEXAMPLES postgres-talk)
set(EXAMPLES postgres-talk)

Comment thread examples/postgres.cpp
});
}
ex::task<pg::results, pg::env> exec2(pg::connection& conn, const char* query) {
PQsendQuery(conn, query);
@dietmarkuehl dietmarkuehl merged commit 7ba58a8 into main May 11, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants