dbind is an experimental database library for C++0x. It provides template metaprogramming facilities for operating on database primitives: lists and tables.
|
Library:
|
cd dbind cmake . make install
g++46 -std=c++0x -O3 example.cc -ldbind
#include <dbind/table.hpp> #include <dbind/display.hpp> #include <dbind/expr.hpp> #include <iostream> using namespace dbind; using namespace std; // Define field names a and b with default types DBIND_FIELD(a, int) DBIND_FIELD(b, char) // Define the schema for a table with the two fields DBIND_SCHEMA(s, (a, b)) int main() { // Creates an instance of a table matching the schema table<s> t; // Insert some rows of data t.push(5, 'x'); t.push(6, 'y'); t.push(7, 'z'); // Display the table cout << display(t) << '\n'; // Select records where a != 6 auto t1 = t.select(_a != 6); cout << display(t1) << '\n'; // Change the value of column a to a + 10 auto t2 = t1.update<a>(_a + 10); cout << display(t2) << '\n'; // Table shorthand auto u = make_table<b, a>(list<char>{ 'z', 'w' }, list<int> { 42, 43 }); // Left join on column b auto t3 = t2.left_join<b>(u); cout << display(t3) << '\n'; return 0; } | _a__b_ 5 x 6 y 7 z _a__b_ 5 x 7 z _a___b_ 15 x 17 z _a___b_ 15 x 42 z |