Fork me on GitHub
#portal
<
2022-10-28
>
Jakub Holý (HolyJak)12:10:54

@djblue hi! Portal does not support Navigable, does it? I tried this

(tap> (->> (next.jdbc/execute! ds ["select * from book"])
             (map #(update % :book/author (fn [v] ^{clojure.core.protocols/nav
                                                    (fn [books key id] (next.jdbc/execute-one! ds ["select * from person where _id=?" id]))}
                                                    [v])))))
and expected that when I click on the vectorized :book/author id, I will see the whole person map but it is just the ["some-id-123"] vector with metadata.

1
wilkerlucio13:10:49

there is support for nav, click on the entry, press v to show the possible views, I don't remember the name but you should see something related to nav there

seancorfield14:10:43

It works for me with next.jdbc -- pressing enter used to nav it but maybe it got broken in a recent release?

djblue15:10:32

I think with nav, you have to click on collection items, not the collection itself.

Jakub Holý (HolyJak)15:10:08

Well it is the collection that is navigable. I had to wrap the item itself in it so that I could assign the necessary Metadata, since the value is string and cannot have them. I will try Enter and v as suggested when back in pc

djblue15:10:06

You should be able to provide the nav fn via the parent map to avoid wrapping the id in a vector.

Jakub Holý (HolyJak)15:10:59

Ah, I thought it must be on the thing itself. That makes sense, will try. Thx!

Jakub Holý (HolyJak)16:10:44

Ok here is what I tried now and does not work (replacing jdbc with a db map):

(let [db {:book [#:book{:id 1, :title "1984" :author 10}]
            :person [#:person{:id 10 :fname "George" :lname "Orwell"}]}]
    (tap> (->> (get db :book)
               (map #(with-meta % {clojure.core.protocols/nav
                                   (fn [_coll key value]
                                     (if (= key :book/author)
                                       (first (filter (comp #{value} :person/id) (:person db)))
                                       value))})))))
In portal when I select the thing I want to be navigable - the author id - and press Enter, I just still see the number. Pressing v shows diff viewers but no nav viewer.

djblue16:10:20

clojure.core.protocols/nav should be quoted I think

1
Jakub Holý (HolyJak)16:10:02

Thank you all for your help!

💯 1
seancorfield19:10:40

@U0522TWDA You could just tell next.jdbc about the :schema where :book/author is an FK to :person/_id ...

🙏 1
seancorfield19:10:29

Then you don't need to post-process the JDBC rows at all.

💯 1