updates to new rdbms

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Tue Mar 7 11:34:35 CET 2006


I've checked in a bug fix of rdbms_index, and 
added some utility functions for indexing in 
rdbms.erl

(1) ix(Value, []) -> [Value].

(2) ix_list(Value, []) when is_list(Value) -> Value.

(3) ix_vals(Obj, PosL) ->
      [[element(P,Obj) || P <- PosL]].

The idea is to not have to write these functions
over and over (or at least once!)

(1) makes a simple value index. You can still make
    it ordered, unique, etc.
(2) expands a list of values and makes each list
    element an index value
(3) is like the snmp indexes. Combine several
    attribute values into one index value.

Example of how to specify them (from the test
suite):

    rdbms:create_table(
      ix_list,
      [{disc_copies, [node()]},
       {attributes, [key, value]},
       {rdbms, 
        [
         {indexes, 
          [{{value,ix},rdbms,ix_list,[],
            [{type,ordered}]}]}
        ]}
       ]),
 
and how to use them:

trans(fun() ->
         mnesia:write({ix_list, 1, [a,b,c]}),
         mnesia:write({ix_list, 2, [c,d,e]}),
         mnesia:write({ix_list, 3, [c,d,e]})
      end),
trans(fun() ->
         [{ix_list,1,[a,b,c]}] = 
            mnesia:index_read(ix_list,a,{value,ix}),
         [{ix_list,1,[a,b,c]}, 
          {ix_list,2,[c,d,e]},{ix_list,3,[c,d,e]}] =
            mnesia:index_read(ix_list,c,{value,ix}),
         [{ix_list,2,[c,d,e]},{ix_list,3,[c,d,e]}] =
            mnesia:index_read(ix_list,d,{value,ix})
      end),


/Ulf W



More information about the erlang-questions mailing list