std.database
Erik Smith via Digitalmars-d
digitalmars-d at puremagic.com
Fri Mar 4 15:55:55 PST 2016
On Friday, 4 March 2016 at 22:44:24 UTC, Sebastiaan Koppe wrote:
> On Friday, 4 March 2016 at 18:42:45 UTC, Erik Smith wrote:
>> auto db = createDatabase("file:///testdb");
>> auto rowSet = db.connection().statement("select name,score
>> from score").execute;
>> foreach (r; rowSet)
>> writeln(r[0].as!string,",",r[1].as!int);
>
> You'll want to have some types in there. As in
>
> struct S
> {
> string name;
> int age;
> }
>
> auto rowSet = db.connection().statement("select name,score from
> score").executeAs!S;
> foreach (r; rowSet) writeln(r.name,",",r.age);
I think some basic object serialization capabilities would be
great although I'm not sure how the bare names can be accessed
like that through the rowSet How would that work? I can see
this:
S s;
auto rowSet = db.connection().statement("select name,score from
score").into(s);
writeln(s.name,",",s.age);
Two other options (not really serialization):
// 1
string name;
int age;
auto rowSet = db.connection().execute("select name,age from
score").into(s.name,age);
foreach (r; rowSet) writeln(name,",",age);
// 2
foreach (r; rowSet) writeln(r["name"],",",r["age"]);
More information about the Digitalmars-d
mailing list