Skip to content
README.md 1.39 KiB
Newer Older
jan.koester's avatar
jan.koester committed
# libdbpp
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
A small C++ database abtraction library
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
## Dependcies
jan.koester's avatar
jan.koester committed
- postgresql(libpq)
- sqlite(sqlite-dev)
- duckdb(duckdb headers)
- C++14
jan.koester's avatar
jan.koester committed
- Cmake
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
### Optional
- Doxygen (for documentation)
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
## Build
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
1. cd libdbpp
2. mkdir build
3. cd build
4. cmake ../
5. make || ninja
jan.koester's avatar
jan.koester committed
6. make install || ninja install
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
## Usage Example
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
```CPP
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
#include <iostream>
#include <dbpp/database.h>
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
int main(int argc,char **argv){
jan.koester's avatar
jan.koester committed
    dbpp::Database db(argv[1],argv[2]);
jan.koester's avatar
jan.koester committed
    dbpp::DBResult res;
    dbpp::SQL sql;
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    sql << "CREATE TABLE IF NOT EXISTS test"
jan.koester's avatar
jan.koester committed
        << "(id INTEGER PRIMARY KEY "
jan.koester's avatar
jan.koester committed
        << db.autoincrement(sql)
        << ",name VARCHAR(255),value TEXT);";
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    db.exec(sql,res);
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    sql.clear();
    res.clear();
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    std::string name,value;
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    std::cout << "Enter Name: " << std::endl;
    std::cin >> name;
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    std::cout << "Enter Value: " << std::endl;
    std::cin >> value;
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    sql << "INSERT INTO test (name,value) VALUES"
        << "('"<< name.c_str() <<"','" << value.c_str() << "');";
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    db.exec(sql,res);
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    sql.clear();
    res.clear();
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    sql << "SELECT name,value FROM test;";
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    int count =db.exec(sql,res);
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
    for(int i=0; i<count; ++i){
        std::cout << "name: " << res[i][0]
                  << " value:" << res[i][1]
                  << std::endl;
    }
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
}
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
```
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
## Build example
```SH
gcc sdbpp.c -o sdbpp -ldbpp 
```
jan.koester's avatar
jan.koester committed

jan.koester's avatar
jan.koester committed
## Usage example
```SH
jan.koester's avatar
jan.koester committed
./sdbpp sqlite /tmp/test.sql
jan.koester's avatar
jan.koester committed
```