StrokeDB's experimental composite metas syntax

Posted by yrashk

I was playing with this idea in my mind for a week or so and finally decided to put it into the code. The basic idea is that since any document can have multiple metas, why not improving API for this? Before latest commits, you needed to do things like:

 
u = User.new :name => "Yurii" 
u.metas << Buyer
u.metas << Seller
u.save!
 

It isn’t really nice. So what I have done just a couple of minutes ago is a special syntax for composite metas. You can simply use Meta#+ to add meta to meta:


User = Meta.new
    # ==> User
Buyer = Meta.new
    # ==> Buyer
Seller = Meta.new
    # ==> Seller
(User+Buyer+Seller).create! :name => "Yurii" 
    # ==> #<User,Buyer,Seller __version__: 5bf2..., name: "Yurii",  uuid: "32ae72c8-a1da-4ead-8bfb-d2aa65e727f3">

where created document will have actually three metas:

_[:__meta__]
    # ==> [#<StrokeDB::Meta __version__: b6a0..., name: "User", uuid:  "292b3226-8c69-4d21-bb2c-d4d8cd924bf2">, #<StrokeDB::Meta __version__:  d223..., name: "Buyer", uuid: "89d4c62a-b935-42c6-b680-78e1de0b7d9e">,  #<StrokeDB::Meta __version__: 2291..., name: "Seller", uuid: "52babc48-5bda-4ea1-a4c3-1c931185c290">]

Also (User+Buyer+Seller).find will work just as expected:


    # ==> [#<User,Buyer,Seller __version__: 5bf2..., name: "Yurii",  uuid: "32ae72c8-a1da-4ead-8bfb-d2aa65e727f3">]

(please note that composition order is important, not only in #find but it also defines a way how combined meta document will look like [Document#meta]).

Please note that this stuff is not fully complete yet, but as always, it is already funny to play with it.

Comments

Leave a response

  1. Michael Christenson IIMarch 27, 2008 @ 09:33 PM

    First of all, great job on this project so far. I’m totally new to your code base. I learned about it yesterday, and I’m just getting into exploring it over the weekend. However I’m extremely excited about the possibilities of StrokeDB.

    Now regarding this article, I was just curious. Why wouldn’t you have a function defined that accepts and array which loops over the array creating the metas? Then a user could simply create the metas as such:

    User.create!(:name => "m3talsmith").metas << %w(Buyer Seller)

    Or the long hand approach of:

    u = User.new(:name => "m3talsmith") u.metas << %w(Buyer Seller) u.save!

    Keep in mind I’m totally new to your code base. But it just seems like the examples you gave contained too much manual labor still. If it’s the labor that you are trying to spare, then it’s best to minimize it as much as possible. Don’t you think?