Fork me on GitHub
#biff
<
2022-11-30
>
Lyn Headley21:11:52

Is it possible to do a pull on an ident? Can't seem to find the right syntax.

Jacob O'Bryant22:11:41

By 'ident' do you mean an attribute-value pair? (XT doesn't have idents like Datomic does). If so you'll have to use q directly, Biff doesn't have a helper for it.

Jacob O'Bryant22:11:53

Maybe I should update biff/lookup so that if there's an even number of args, it treats the second one as a pull expression. so you could call it like (biff/lookup db '[* {:foo/bar [*]}] :baz "quux")

Lyn Headley22:11:02

That's exactly what I want!!!

Jacob O'Bryant22:11:35

Here ya go 🙂 (haven't tested it yet)

(defn lookup [db & args]
  (let [[pull-expr & kvs] (if (odd? (count args))
                            args
                            (conj args '[*]))]
    (ffirst (xt/q db {:find [(list 'pull 'doc pull-expr)]
                      :where (vec
                              (for [[k v] (partition 2 kvs)]
                                ['doc k v]))}))))
I'll throw this into the next biff release; in the mean time you can copy it into your project somewhere.

macrobartfast21:12:13

I didn’t know about biff/lookup… nice!

macrobartfast21:12:37

I need to actually read all the biff source soon.

Lyn Headley22:12:20

I think that one is in the official docs

macrobartfast22:12:34

haha… I’m busted!

Lyn Headley22:12:13

Heh. I forgot most of what I read in the docs. Trying to read twice.

Jacob O'Bryant22:12:56

that's a link to the old docs FYI, new ones are here: https://biffweb.com/docs/api/xtdb/

macrobartfast22:12:22

But I just memorized them all!!

Jacob O'Bryant22:12:36

(is there a link to that somewhere on the website or did you have it bookmarked or something?)

macrobartfast22:12:49

lemme figure out how I got there…

Jacob O'Bryant22:12:53

:) fortunately the concerns are mostly all the same

macrobartfast22:12:25

I had googled site: biff/lookup

Jacob O'Bryant22:12:07

ah, that would do it

macrobartfast22:12:22

You will need to hand write a letter to Google.

Jacob O'Bryant22:12:28

I can't hide my old files from them

macrobartfast22:12:07

the EU is about to pass the Right For Old Docs To Be Forgotten bill, so no worries.

1