std.database

Erik Smith via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 3 10:08:26 PST 2016


On Thursday, 3 March 2016 at 17:03:58 UTC, Kagamin wrote:
> On Thursday, 3 March 2016 at 15:53:28 UTC, Erik Smith wrote:
>> auto r = db.connection().statement("select from t").range();  
>> // nouns
>
> db.execute("select from t").range();
> `range` is probably ok.
> Or
> auto connection = db.createConnection();
> connection.execute("select from t").range();
>
>> auto r = db.getConnection().getStatement("select from 
>> t").getRange();  // verbs
>
> Getters must be actually nouns, but these are not getters, but 
> factory methods: createConnection, createStatement, probably 
> low level and/or private.

Good point.   I will track this as a design option to debate.

> db.execute("select from t").reader; //row range
> db.execute("select from t").get!long; //scalar
> db.execute("select from t"); //non-query

More good options (the 3rd one is there).   Also at the value 
access level there are several options to consider: v.get!long, 
v.as!long, v.to!long, etc.

> On the other hand execute can simply return the reader with 
> extra getter for scalar
> result. Just don't do stuff until it's iterated. Is it possible?
> auto rows = db.execute("select * from t");

I'm hedging a bit on this because there are other capabilities 
that need to be introduced that might present a problem.   
Another issue is that this might conflict with the notion of a 
container and the use of opSlice.  Great feedback though and I'm 
tracking it.

erik




More information about the Digitalmars-d mailing list