Skip to content
C++ client library for PostgreSQL
C++ Python CMake Makefile Shell
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.conan Modernize namespaces Mar 11, 2019
cmake Rename project Nov 29, 2018
doc Improve documentation. Apr 1, 2019
include/tao Add missing noexcepts Mar 27, 2019
src Add missing noexcepts Mar 27, 2019
.appveyor.yml #12 Build as C++ project Nov 29, 2018
.clang-format Update Nov 10, 2018
.gitignore New Mar 27, 2016
.travis.yml Add GCC 9 May 27, 2019
CMakeLists.txt Style Nov 29, 2018
LICENSE Update copyright. Mar 19, 2019
Makefile Modernize namespaces Mar 11, 2019
README.md Add a quick status section, see #16 Jun 25, 2019
conanfile.py #12 Export all symbols on Windows Nov 30, 2018

README.md

Welcome to taoPQ

Release TravisCI AppVeyor Coverage Language grade: C/C++

taoPQ is a light-weight C++ client library for accessing a PostgreSQL database, providing a modern wrapper for libpq. It has no dependencies beyond a C++17 compatible compiler and the PostgreSQL libpq client library.

Documentation

Introduction

This library provides classes for database connections and transactions, as well as connection pools and table writers. It also supports for prepared statements and nested transaction. An extensible traits mechanism is used to convert C++ types into SQL statement parameters, and conversely to convert query results into arbitrary C++ types. The following example shows the basic look and feel of the library.

#include <cassert>
#include <iostream>

#include <tao/pq.hpp>

int main()
{
  // Open connection
  const auto conn = tao::pq::connection::create( "dbname=template1" );

  // Execute SQL statement
  conn->execute( "DROP TABLE IF EXISTS taopq_example" );
  conn->execute( "CREATE TABLE taopq_example ( a INTEGER PRIMARY KEY, b INTEGER, c TEXT NOT NULL )" );

  // Prepare statement
  conn->prepare( "my_stmt", "INSERT INTO taopq_example VALUES ( $1, $2, $3 )" );

  {
    // Begin transaction
    const auto tr = conn->transaction();

    // Execute statement with parameters
    tr->execute( "INSERT INTO taopq_example VALUES ( $1, $2, $3 )", 1, 42, "foo" );

    // Execute previously prepared statement with parameters (recommended)
    tr->execute( "my_stmt", 2, tao::pq::null, "Hello, world!" );

    // Commit transaction
    tr->commit();
  }

  // insert/update/delete statements return an object that contains the number of rows affected
  {
    const auto res = conn->execute( "insert", 3, 3, "drei" );
    assert( res.rows_affected() == 1 );
  }

  // Queries return object with result set
  const auto res = conn->execute( "SELECT * FROM taopq_example" );
  assert( res.size() == 3 );

  // Conveniently convert result into C++ container
  const auto v = res.vector< std::tuple< int, std::optional< int >, std::string > >();
}

Status

The library was successfully tested with

  • GCC 7+
  • Clang 5+
  • Visual Studio 2017 (v15.9)

Older versions of Visual Studio might work, 15.4 is known not to work. Let us know if you try any version between 15.4 and 15.9 and whether it works or not.

Contact

taoPQ is part of The Art of C++.

For questions and suggestions about taoPQ please contact the authors at taocpp(at)icemx.net.

License

taoPQ is certified Open Source software. It may be used for any purpose, including commercial purposes, at absolutely no cost. It is distributed under the terms of the MIT license reproduced here.

Copyright (c) 2016-2019 Daniel Frey and Dr. Colin Hirsch

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You can’t perform that action at this time.