Proposal: Database Engine for D

Kapps via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 1 02:40:59 PST 2016


On Friday, 1 January 2016 at 10:26:14 UTC, Russel Winder wrote:
> On Fri, 2016-01-01 at 10:00 +0000, Kapps via Digitalmars-d 
> wrote:
>> On Thursday, 31 December 2015 at 17:14:55 UTC, Piotrek wrote:
>> > 
>> >   struct Person
>> >   {
>> >    string name;
>> >    string surname;
>> >    ubyte age;
>> >    Address address;
>> >   }
>> > 
>> >  DataBase db = new DataBase("file.db");
>> >  auto coll = db.collection!Person("NSA.Registry");
>> >  auto visitationList = coll.filter!(p => p.name == "James");
>> >  writeln (visitationList);
>> 
>> This example shows the difficulty of doing this in D. You 
>> can't really have something like `p.Name == "James"`, or 
>> `p.Age < 21` translate to SQL properly without language 
>> changes, which I believe Walter or Andrei were against. This 
>> has been the key problem when things like Linq to Sql for D 
>> have been brought up before.
>
> Why does it need language changes?
>
> Having the ability to have an internal DSL instead of SQL 
> string fiddling is one of the major wins for SQLAlchemy. If it 
> can be done in Python why can't it be done in D?

Someone else can explain better / more correctly than me, but I 
believe the issue lies with opCmp and opEquals. You can make 
expressions like p.Name.equals("James") work (I believe using 
opDispatch), but because all you have is opEquals, you can't know 
if the user put in 'p.Name == "James"` or `p.Name != "James"`, as 
they both simply call opEquals. In order to do that, you would 
need things like opLessThan, opEquals, opNotEquals, 
opGreaterThan, etc, which would (with improper use or bugs) cause 
other issues, like a < b && a > b and a == b && a != b to be 
true, or a == b || a != b to be false.

I'm also not certain how you could implement `p => p.Name == 
"James" || p.Name == "Bob"`, but there might be a way? I think 
this is the gist of it, but I'm likely wrong on some aspects of 
this, so it would be good if someone else clarified..


More information about the Digitalmars-d mailing list