Alexander Burger <a...@software-lab.de> writes:

Hi Alex,

>> assume I have a (hypothetical) database with objects of class +Thing
>> that have relations defined like this:
>> 
>> #+name: myBag
>> #+BEGIN_SRC picolisp
>> (rel stamp (+Bag)
>>    ((+Symbol))                          # timestamp-type
>>    ((+Ref +Date))                       # start date
>>    ((+Time)) )                          # start time
>> #+END_SRC
>> 
>> e.g.
>> 
>> ,--------------------------
>> | stamp (active 735458 NIL)
>> `--------------------------
>> 
>> #+name: myListBag
>> #+BEGIN_SRC picolisp
>> (rel props (+List +Bag)
>>    ((+Ref +String))                     # Key
>>    ((+String)) )                        # Value
>> #+END_SRC
>> 
>> e.g.
>> 
>> ,--------------------------------------------------------
>> | props (("key1" "val1") ("key2" "val2") ("key3" "val3"))
>> `--------------------------------------------------------
>> 
>> #+name: myStringList
>> #+BEGIN_SRC picolisp
>> (rel tags (+List +Ref +String))
>> #+END_SRC
>> 
>> e.g.
>> 
>> ,----------------------------
>> | tags ("tag1" "tag2" "tag3")
>> `----------------------------
>> 
>> 
>> Now, how can I query the DB from a program, using these relations? E.g.
>> 
>> 1. Find objects with an active (time)stamp with date 735458?
>> 2. Find objects with props with key 'key1' and value 'val1' or 'val2'
>>    for this key?
>> 3. Find objects with tags 'tag1' and 'tag3'?
>
>
> The simplest is using 'collect' (not tested):
>
>    (collect 'stamp '+Thing 735458)
>
>    (filter
>       '((This)
>          (find
>             '((L)
>                (and
>                   (= "key1" (car L))
>                   (member (cadr L) '("val1" "val2")) ) ) )
>             (: props) )
>       (collect 'props '+Thing "key1") )
>
>    (sect
>       (collect 'tags '+Thing "tag1")
>       (collect 'tags '+Thing "tag2") )

Ok, so I use Lisp and not Pilog.
This looks good and reasonably simple - thanks! I have to try ...

PS
I did not know about the 'sect' function, definitely useful.

-- 
cheers,
Thorsten

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to