Boost logo

Boost :

From: Brock Peabody (brock.peabody_at_[hidden])
Date: 2005-08-03 15:02:00


Sorry for the late reply, my filter threw this message in the trash bin.

> -----Original Message-----
> From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]]
> On Behalf Of Caleb Epstein
>
> On 7/28/05, Brock Peabody <brock.peabody_at_[hidden]> wrote:
>
> > table("customer") [
> > *field("id") = &customer::id,
> > field("name") = &customer::name,
> > field("number") = &customer::number,
> >
> > table("tax_exempt")[
> > -field("customer"),
> > field("state_id") = &tax_exempt_data::state_id
> > ]
> > = &customer::tax_exempt
> > ];
>
> I assume 'customer' is a class with data members id, name, number?

Exactly. I tried to keep the example as short as I could. You can
assign the above expression to a serializer:

   serializer<customer> s = table(....

      //loads all customers named Bob
   std::vector<customer> customers =
      s.load<std::vector<customer> >(database, "name = 'Bob'");

      //throws if more than one
   boost::optional<customer> c =
      s.load<boost::optional<customer> >(database, "id = 5");

Usually in a case like this customer wouldn't have an id field, it would
be the key to a map:

   typedef std::map<int,customer> customer_map;

   typedef std::pair<int,customer> pair_type;

   serializer<pair_type> s =
      table("customer") [

         *field("id") = &pair_type::first
         field("name") = &customer::name,
      
         ...
      ];

   customer_map m = s.load<customer_map>(db, "id < 50");
   
>
> [...]
>
> > If any of that sounds useful I'd love to help out.
>
> It sounds very useful! Are you planning on sharing the code you've
> written, or would this be a start-from-scratch approach?

Thanks!

I'll share all I've learned but it might be better to start from
scratch. I've made too many assumptions that are true in my world but
not in general and we can probably come up with a better syntax than
what I've got.

Where do you think would be a good place to start? I could put together
and post an abstract database interface with a postgresql implementation
for starters.

Brock


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