Boston D Meetup: Strawman Structs
Steven Schveighoffer via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Tue Jul 25 06:16:47 PDT 2017
On 7/25/17 6:15 AM, Nicholas Wilson wrote:
> On Tuesday, 25 July 2017 at 09:50:46 UTC, John Colvin wrote:
>> On Sunday, 2 July 2017 at 10:35:49 UTC, Steven Schveighoffer wrote:
>>> I'll have a short presentation on a weird trick I discovered while
>>> writing some MySQL serialization code. Hope you can attend!
>>>
>>> https://www.eventbrite.com/e/d-lang-presentation-strawman-structs-tickets-35120523431
>>>
>>>
>>
>> Is there a written summary of the idea? Or is there a specific point
>> in the video someone could point me to?
>
> Basically using structs to describe layouts (among other relations) and
> in turn use that to drive DbI automated code. The DbI is the only "code"
> the rest is declarative using the type system.
>
> Steven was using it to describe what columns ( name and type) a query
> should return from a DB and the using DbI to generate the Query.
>
Not exactly :)
I wrote a database serializer that uses introspecting members, types,
and attributes of a struct to correctly populate members of the struct
with data from the rows. So yes, I'm using introspection, but only for
the serialization, the query is hand-written.
In some cases (particularly when you are joining 2 tables that have
conflicting columns), I needed to change how the serialization worked
(e.g. the column names had to change).
In order to do this, I created descriptors that are built from the
combination of attributes and other introspected items. Then my thought
was I would pass in the descriptors directly in order to control how
serialization works.
I found it unwieldy and difficult to write the low-level descriptors by
hand. But I thought of making a dummy or strawman struct with all the
attributes the way I wanted, and still serializing to the real struct.
It worked really well.
I also go over some other possible ideas for using this concept. Start
watching from here: https://youtu.be/ZxzczSDaobw?t=18m24s
Andrei suggested doing a blog article (and actually I had started
writing one, but it turned into this talk instead). I'll probably still
do this.
-Steve
More information about the Digitalmars-d-announce
mailing list