Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rafaeljusto/dbplus
C++ database interface
https://github.com/rafaeljusto/dbplus
Last synced: about 9 hours ago
JSON representation
C++ database interface
- Host: GitHub
- URL: https://github.com/rafaeljusto/dbplus
- Owner: rafaeljusto
- License: gpl-3.0
- Created: 2011-11-16T17:13:09.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2012-04-08T23:56:03.000Z (over 12 years ago)
- Last Synced: 2024-05-01T20:39:42.781Z (7 months ago)
- Language: C++
- Homepage:
- Size: 180 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
DBplus
=======**DBplus** is a C++ database interface to use the most common database
clients, such as MySQL and PostgreSQL
.Prerequisits
------------* g++ 4.6 -
* python 2.7 -
* scons 2.0 -
* libboost-system-dev 1.4 -
* libboost-test-dev 1.4 -
* libboost-date-time-dev 1.4 -
* libmysqlclient-dev 5.1 -
* libpq-dev 5 -The project was compiled using the above compilers and libraries,
higher versions should work well.To run the unit tests:
* install mysql-server package (MySQL)
* install postgresql package (PostgreSQL)
* create a root user with the password "abc123" on each database server
* create a database with the name "dbplus" on each database serverInstallation
------------Define the compiler using the CXX environment variable, by default
is used "g++".# scons
# scons installFor API documentation:
# scons doc
Usage
-----Source code (using MySQL):
#include
#include
#include
#include
#include#include
#include#include
#includeclass Object
{
public:
Object() : _id(0), _value("") {}void print()
{
std::cout << "-----------------" << std::endl;
std::cout << "Id: " << _id << std::endl;
std::cout << "Value: " << _value << std::endl;
std::cout << "Date: " << _date << std::endl;
}void setId(const long id)
{
_id = id;
}void setValue(const std::string &value)
{
_value = value;
}void setDate(const boost::posix_time::ptime &date)
{
_date = date;
}private:
long _id;
std::string _value;
boost::posix_time::ptime _date;
};int main()
{
dbplus::MySql mysql;
mysql.connect("dbplus", "root", "abc123", "127.0.0.1");std::string sql = "SELECT id, value, date FROM test";
std::shared_ptr result =
std::dynamic_pointer_cast(mysql.execute(sql));std::list objects =
result->getAll([](std::map row) {
Object object;
object.setId(boost::any_cast(row["id"]));
object.setValue(boost::any_cast(row["value"]));
object.setDate(boost::any_cast(row["date"]));
return object;
});for (Object object: objects) {
object.print();
}
}Compiling:
g++ -std=c++0x test.cpp -o test -ldbplus -lboost_date_time -lmysqlclient
Output:
-----------------
Id: 1
Value: This is a test
Date: 2011-Nov-11 11:11:11Contact
-------Rafael Dantas Justo
License
-------CGIplus Copyright (C) 2012 Rafael Dantas Justo
This file is part of CGIplus.
CGIplus is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.CGIplus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.You should have received a copy of the GNU General Public License
along with CGIplus. If not, see .