Skip to content

mastergberry/sqlpp11-connector-postgresql

 
 

Repository files navigation

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.

About

PostgreSQL connector for sqlpp11 library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 90.5%
  • CMake 5.3%
  • Python 2.8%
  • C 1.4%