Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

matthijs/sqlpp11-connector-postgresql

Repository files navigation

Archived

This library is now integrated into sqlpp11 and so this library is now archived.

sqlpp11-connector-postgresql

PostgreSQL connector for sqlpp11 library

License

sqlpp11 is distributed under the BSD 2-Clause License.

Status

Build Status Build status codecov Codacy Badge Join the chat at https://gitter.im/sqlpp11/Lobby

Examples

An example on how to use this library

auto config = std::make_shared<sqlpp::postgresql::connection_config>();
config->host = "127.0.0.1";
config->user = "someuser";
config->password = "some-random-password";
config->dbname = "somedb";

sqlpp::postgresql::connection db(config);

TabFoo foo;
for(const auto& row: db(select(foo.name, foo.hasFun).from(foo).where(foo.id > 17 and foo.name.like("%bar%"))) {
  std::cerr << row.name << std::endl;
}

The library supports also 'ON CONFLICT'. This way INSERT or UPDATE can be implemented. To use it one can use it with the following code:

auto config = std::make_shared<sqlpp::postgresql::connection_config>();
config->host = "127.0.0.1";
config->user = "someuser";
config->password = "some-random-password";
config->dbname = "somedb";

sqlpp::postgresql::connection db(config);

TabFoo foo;
db(insert_into(foo).default_values().on_conflict().do_nothing());
db(insert_into(foo).default_values().on_conflict(foo.id).do_nothing());
db(insert_into(foo).default_values().on_conflict(foo.id).do_update(foo.name = "some data", foo.hasFun = true);
db(insert_into(foo).default_values().on_conflict(foo.id).do_update(foo.name = "some data", foo.hasFun = true).where(foo.hasFun == false));

The only limitation in on_conflict() is the conflict_target. Only a column is supported in the conflict_target. If there is need for a more sophisticated conflict_target please create an issue.

Connection configuration

You can use all possible authentication options that are available in PostgreSQL. See here for more information about the options.