Boost logo

Boost :

Subject: Re: [boost] sqlpp11: SQL for C++
From: Roland Bock (rbock_at_[hidden])
Date: 2013-11-11 08:15:32


On 2013-11-11 13:40, Larry Evans wrote:
> On 11/11/13 04:49, Thorsten Ottosen wrote:
>> On 09-11-2013 23:03, Roland Bock wrote:
>>> Hi,
>>>
>>>
>>> sqlpp11 is a template library representing an embedded domain specific
>>> language (EDSL) that allows you to
>>>
>>> * define types representing tables and columns,
>>> * construct type safe queries checked at compile time for syntax
>>> errors, type errors, name errors and even some semantic errors,
>>> * interpret results by iterating over query-specific structs with
>>> appropriately named and typed members.
>>
>> Very interesting.
Thanks :-)
>>
>> Have you considered a syntax like
>>
>> auto results = db >> select(Person.name,Person.age) >> from(foo) >>
>> where( Person.age > 42);
>>
>> -Thorsten
>>
> Or maybe using << instead of >>. The reason for using << is it's
> suggestive of karma operators. I'm also guessing that:
>
> auto results =
> db << select(Person.name,Person.age)
> << from(foo)
> << where( Person.age > 42);
>
> would be translated into some SQL string that is then passed
> to the actual dbms thru the connection and the result is
> then returned. This again sounds vaguely like what
> karma does, only karma just formats the data structure
> into a string. Was karma ever considered as part of the
> implementation?
>
> -Larry

I experimented with such a syntax in 2010 (using <<) and I prefer the
member functions personally. The reason is that if you have

auto s1 = select(Person.name, Person.age);
auto s2 = s1.from(Person);
auto s3 = s2.where(Person.age > 42);

then s1, s2 and s3 have different types (sqlpp is creating template
expression trees). I would not expect this to happen in case of stream
operators.

I have no real knowledge of boost.karma, to be honest. So I can't really
tell whether or it would be useful in this context.

I understand that boost.proto could be helpful in creating the EDSL and
processing such trees. I tried to use boost.proto in 2010 but failed to
wrap my head around it (and then gave up due to the compile times).
During Meeting C++ in Dusseldorf last weekend, Eric encouraged me to try
again, when there is a full C++11 version of proto :-)

Feel free to jump in and give it a try with karma or proto or both :-)

Regards,

Roland


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk