Giter Club home page Giter Club logo

picopq's Introduction

PicoPQ

Tiny C++17 wrapper for libpq providing a binary interface to PostgreSQL.

Dependencies

  • libpq

Usage

The table created using:

CREATE TABLE characters( id bigint, name text );

can be queried with:

#include <ppq.h>

try
{
    ppq::connection connection( "postgresql://user:password@server/database" );

    ppq::result result = connection.execute( "SELECT id, name FROM characters WHERE id = $1", 1ll );
    for ( ppq::row row : result )
        std::cout << row.at< int64_t >( 0 ) << " - " << row.at< char const* >( 1 ) << std::endl;
}
catch ( ppq::exception const& e )
{
    std::cout << e.what() << std::endl;
}

There is also a way to prepare queries:

connection.prepare( "get_character", "SELECT id, name FROM characters WHERE id = $1" );
connection.execute_prepared( "get_characters", 1ll );

Parameters of type std::vector are also supported:

std::vector< int64_t > ids{ 1ll, 2ll };
ppq::result result = connection.execute( "SELECT name FROM characters WHERE id = ANY($1)", ids );

Extensions

Other types can be added by providing a specialization of

template< typename T >
constexpr T to_network( T value );

which should return the data in a format that can be sent over the wire and

template< typename T >
constexpr T from_network( char const* value );

which will construct an object from the network data. By default it tries to call the constructor T( char const* ).

picopq's People

Contributors

okoz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.