Skip to content

Instantly share code, notes, and snippets.

@cszawisza
Created June 9, 2015 18:11
Show Gist options
  • Save cszawisza/054a94c527cd86afb1a5 to your computer and use it in GitHub Desktop.
Save cszawisza/054a94c527cd86afb1a5 to your computer and use it in GitHub Desktop.
#include <sqlpp11/sqlpp11.h>
#include <sqlpp11/postgresql/connection.h>
using namespace std;
std::shared_ptr<sqlpp::postgresql::connection_config> getConf(){
auto conf = std::shared_ptr<sqlpp::postgresql::connection_config>( new sqlpp::postgresql::connection_config );
conf->host = "localhost";
conf->dbname = "postgres";
conf->user = "postgres";
conf->password = "postgres";
conf->debug = true;
return conf;
}
namespace users_ {
struct C_uid {
struct _alias_t {
static constexpr const char _literal[] ="c_uid";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t {
T c_uid;
T &operator()() { return c_uid; }
const T &operator()() const { return c_uid; }
};
};
using _traits = sqlpp::make_traits<sqlpp::integer>;
};
struct Name {
struct _alias_t {
static constexpr const char _literal[] ="name";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t {
T name;
T &operator()() { return name; }
const T &operator()() const { return name; }
};
};
using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>;
};
}
struct users : sqlpp::table_t<users,users_::C_uid, users_::Name> {
using _value_type = sqlpp::no_value_t;
struct _alias_t {
static constexpr const char _literal[] = "users";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t {
T users;
T &operator()() { return users; }
const T &operator()() const { return users; }
};
};
};
int main()
{
sqlpp::postgresql::connection db ( getConf() );
users u;
db(select( count(u.c_uid), u.name ).from(u).where( u.name.like("%xxx%")));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment