sqlpp11

One of the new kids on the block, sqlpp11 provides an embedded domain specific language (eDSL) approach to calculate your sql queries etc. at compile time, in a guaranteed type safe way.

As a result, you can write sql-code just in your c++ files, like the following example taken from the project’s website:

for (const auto& row : db(select(sum(id).as(total)).as(foo.id)).from(tab))) {
   std::cout << row.total << std::endl;
}

The benefit’s are obious: no more wrong types in comparisons, you cannot construct semantically wrong SQL expressions (yes, the c++ compiler will tell you!), direct integration into the language core (range-based for and friends), and much more.

However – like anything – it has it’s price: being a compile-time animal, you cannot construct queries during runtime, i.e. by taking information from a textual representation, or introspecting a given table on a particaluar database. Thus, it’s a bit hard to write dynamically adapting software, but you shall have a non-chaning database layout, and need possible SQL queries/insertions/modifications/deletions defined at compile time.

Checking out the github repo, and reading the wiki for the project, you can see that backends for mysql, sqlite3 and postgres are in place. A special goodie is that you can even run sql against the STL, assuming you install the stl-connector. Things like having a std::vector now enable you to select or modify from that vector by using SQL semantics. Great!

What I really like about sqlpp11

What I don’t like

Roman’s Rating: 4.7 / 5.0

Information

Update:

Roland Bock made a comment on 10.11.2014 13:29:

I just stumbled over your post, thanks! Please let me add, that you might want to take a look at the following section

Dynamic Select

It shows how to write select statements in case you do not know the full structure of the query in advance. Admittedly, it will get less pleasant, the less you know at compile time. This aspect of the library is not feature complete and not fully documented yet, but you can construct almost everything at runtime now.

Regards, Roland

@roland: thanks, excellent!