H1 2015 - db access support in Phobos

FG via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 3 08:42:17 PST 2015


On 2015-02-03 at 16:30, Daniel Kozák via Digitalmars-d wrote:
> V Tue, 03 Feb 2015 15:20:40 +0000
> Vadim Lopatin via Digitalmars-d <digitalmars-d at puremagic.com> napsáno:
>> Update in v0.2.19: you can specify field list for select
>>
>>       writeln("reading all user table rows, but fetching only id
>> and name (you will see default value 0 in flags field)");
>>       foreach(ref e; stmt.select!(User, "id", "name")) {
>>           writeln("id:", e.id, " name:", e.name, " flags:",
>> e.flags);
>>       }
>>
>> output:
>>
>> reading all user table rows, but fetching only id and name (you
>> will see default value 0 in flags field)
>> id:1 name:John flags:0
>> id:2 name:Andrei flags:0
>> id:3 name:Walter flags:0
>> id:4 name:Rikki flags:0
>> id:5 name:Iain flags:0
>> id:6 name:Robert flags:0
>>
> This is dangerous zone, you shoud not do this ;-). In my work I have
> writen our ORM-like db layer which has this funcionality (mainly
> performance reasons) but if I can go back in time. I will be against
> such a misfeature.
  

A misfeature? If the ORM only allowed SELECT *, it wouldn't be of much use with records containing blobs or big amounts of other data. If the object was retrieved only for read and to update a few fields, pulling all columns would be very wasteful.

So now, for the purpose of performing an update, each field could be marked as dirty (if its value has changed) or inconsistent (if it wasn't pulled from the database at all). And BTW, each should be Nullable to prevent loss of information for columns that aren't marked as NOT NULL. ORM easily becomes complicated...


More information about the Digitalmars-d mailing list