Connections

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. Handling of error and warning messages, for example, is defined by pqxx::errorhandler objects in the context of a connection. Prepared statements are also defined here.

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.