On 2013-11-11 15:06, Larry Evans wrote:
On 11/11/13 02:36, Roland Bock wrote:
On 2013-11-11 01:47, Larry Evans wrote:
On 11/10/13 18:02, Larry Evans wrote:
On 11/09/13 16:03, Roland Bock wrote:
Hi,
over the last four or five years I developed several SQL libraries for C++. With C++11 I was finally able to create an SQL library that meets my own expectations and requirements. It is being used in production, I recently put it on github, and I would really like to hear from you guys whether this is something that could be interesting for you personally or for boost?
https://github.com/rbock/sqlpp11 https://github.com/rbock/sqlpp11/wiki
[snip] The code here:
https://github.com/rbock/sqlpp11/blob/master/include/sqlpp11/table_base.h
contains:
template
struct table_base_t : public ColumnSpec::_name_t::template _member_t >... {...}; which looks like it declares a table row, where the columns come from ColumnSpec...
In understanding how the library works, this is probably one of the crucial parts. As you guessed correctly, it declares the innards of a table class. The somewhat convoluted looking inheritance adds columns as members to the class. The
column_t
instantiates a column class with all required information like the value type, whether it can be NULL, its textual representation, etc. The ColumnSpec also contains a template like this:
template<typename T> struct _member_t { T foo; };
Inheriting from an instance of this template adds a member with the respective name (foo in this example) to derived class. Thus, the code you cited adds objects representing columns as appropriately named members to the table class.
Ah. I see. So tab_sample, if declared as:
TabSample tab_sample;
where TabSample is from:
https://github.com/rbock/sqlpp11/blob/master/tests/TabSample.h
could be used in expressions like:
tab_sample.alpha; tab_sample.beta; tab_sample.gamma;
Nice! Makes meaningful column names.
Exactly! And this is transported into the result rows as well, e.g. for (const auto& row: db.run(select(all_of(tab_sample)).from(tab_sample))) { std::cerr << row.alpha << '\n'; std::cerr << row.beta << '\n'; std::cerr << row.gamma << '\n'; } And they also have appriate types of course :-)
However, instead of table_base_t, would maybe row_base_t be a better name since it's really a row in a table?
It is a set of columns, which more or less represents a table (if you ignore indexes and foreign keys, etc). So I wouldn't say that it is a row.