Feature Complete Software
Articles Open Source Contact

SOCI Article in this Month's Dr. Dobb's

It's been about a year and a half since I first came across SOCI, an open source database library for C++. SOCI was created by Maciej Sobczak. I've always wished for an easy to use database library for C++, and when I saw SOCI I was very excited by its potential. I made some suggestions to Maciej, and when I wrote some code implementing a few new features, he graciously invited me to join the project.

My initial work on SOCI was primarily to add support for bulk operations and dynamic descriptions of result sets. Along the way I stumbled upon a simple but useful application of C++ traits which allows SOCI to be seamlessly integrated with arbitrary user defined types. The key to this is a traits class called TypeConversion.

This means, for example, if your code base makes use of your own homegrown Date, String, or Money class, you can define a TypeConversion in just one place, and then use these classes directly everywhere your code interfaces with SOCI.

As a bonus, I was able to extend the TypeConversion technique to give SOCI support for Object Relational mapping. In this case, you simply define a TypeConversion which maps fields in your object to the names of columns returned by a database query.

This is all described in detail in my article "Supporting Custom C++ Types", in the July issue of Dr. Dobb's Journal.

I think the use of traits for this purpose was particularly well-suited to a relational database library, but it is my hope that the techniques described in the article might be found generally useful. I'm very interested to hear from readers who have applied this technique in other problem domains.

Posted by Steve Hutton on Wed, 14 Jun 2006 23:00:00 +1700 [Permalink] [More on SOCI]

Previous: Welcome
Next: Python Web Frameworks

Related Links:

SOCI Database Library
Dr. Dobb's - Supporting Custom C++ Types


Post a comment

Your Name:

Comment: