Proposal: Database Engine for D

Sebastiaan Koppe via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 4 03:14:36 PST 2016


On Monday, 4 January 2016 at 07:48:14 UTC, Jacob Carlborg wrote:
> Perhaps I'm missing something obvious but there are several 
> problems with this:
>
> 1. What happens when you use more than one query for the same 
> table at the same scope? In the above case, "Person" is already 
> defined the second time "db" is invoked. It's not possible to 
> add fields for already declared structs. Unless you use some 
> form of opDispatch backed by an associative array of variants

While it wasn't apparent, when I said "later" I meant "later" in 
git's history. The second version would be in a future commit, 
i.e. when changes are made. Then you can diff it and generate 
migration code. (Obviously this requires the DSL to be in a 
separate file without other code. We used to have such a 
reflective system in place in our continuous deployment. It would 
look at the changes in git since the last deployment and when 
certain files changed it knew it had to do certain stuff.)

> 2. What happens if I want to execute a custom query in a 
> function, i.e. a query that is only used once. Will it generate 
> the sturct inside the function or am I forced to always use 
> this mixin at module level?

I suppose you need to declare each and every query in the DSL. 
But you might be on to something ugly in what I am proposing.

Having said that, facebook seems to be going the DSL route. 
https://facebook.github.io/graphql and 
https://facebook.github.io/react/blog/2015/05/01/graphql-introduction.html

Another benefit of a DSL is that you can generate code for other 
languages. For instance you could generate a JS, Swift or Android 
client.

> I still think it's a lot easier to declare the struct with 
> standard D code. I don't think the DSL adds any value in this 
> case. Just do something like:
>
> @db struct Person
> {
>     string name;
>     int age;
> }
>
> The @db attribute would allow to create the migrations.

But then you are back to square one with regards to queries.


More information about the Digitalmars-d mailing list