libpqxx
The C++ client library for PostgreSQL
|
Use of the libpqxx library starts here.
Everything that can be done with a database through libpqxx must go through a pqxx::connection object. It connects to a database when you create it, and it terminates that communication during destruction.
Many things come together in this class. For example, if you want custom handling of error andwarning messages, you control that in the context of a connection. You also define prepared statements here. For actually executing SQL, however, you'll also need a transaction object which operates "on top of" the connection. (See Transaction classes for more about these.)
When you connect to a database, you pass a connection string containing any parameters and options, such as the server address and the database name.
These are identical to the ones in libpq, the C language binding upon which libpqxx itself is built:
https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
There are also environment variables you can set to provide defaults, again as defined by libpq:
https://www.postgresql.org/docs/current/libpq-envars.html
You can also create a database connection asynchronously using an intermediate pqxx::connecting object.