Database interface design - was how to build up the library.

Piotr Szturmaj bncrbme at jadamspam.pl
Fri Oct 7 10:02:40 PDT 2011


Andrei Alexandrescu wrote:
> 1. MFC had at a point a wizard that generated one struct per resultset.
> It was an absolute maintenance disaster and they recanted by offering
> dynamically-bound result sets. The lesson there is that defining a
> struct for each query won't likely play out, so we better use
> Tuple!(ColType1, ColType2, ...). A possible API would be:
>
> auto db = std.database.connect("cdb.mysql");
> auto rows = db.sql!(double, ulong)
> ("SELECT SUM(x), COUNT(x) FROM table");
> // We know that rows is a range of Tuple!(double, ulong).
> writeln("Sum is ", rows.front[0], " count is ", rows.front[1]);
>
> Cool beans. I'd love to use such an API!
> Andrei

Did you see http://pszturmaj.github.com/ddb/db.html ? It maps tuples, 
structs and arrays in similar manner.


More information about the Digitalmars-d mailing list