mpdairy / posh

A luxuriously simple and powerful way to make front-ends with DataScript and Reagent in Clojure.
Eclipse Public License 1.0
460 stars 45 forks source link

Pull-many support + vectors as query values #39

Closed Quezion closed 4 years ago

Quezion commented 4 years ago

Adds support for pull-many in the Posh API. Includes a basic test included below to demonstrate usage.

(let [conn (dt/create-conn)
      _ (d/posh! conn)
      ents [{:a "foo" :b 42}
            {:a "bar" :b 52}
            {:a "baz" :b 62}]
      tran (d/transact! conn ents)
      eids (->> (d/q '[:find ?e
                       :where [?e :a _]] conn)
                deref
                (reduce into [])
                reverse)
      ;;dtlg-raw (dt/pull-many (dt/db conn) '[*] eids)
      entity-reaction (d/pull-many conn '[*] eids)]
  (is (= ents (map #(select-keys % [:a :b]) @entity-reaction))
      "Entities in reaction should match input entities against input sequence of eids")
  (let [updated-ents (vec (map #(update % :b inc) @entity-reaction))]
    (d/transact! conn updated-ents)
    (is (= updated-ents @entity-reaction)
        "Entities in reaction should updated after transact")))

I noticed that pull-many-analyze already existed, so my only change there was using Datomic's official pull-many function. I added similar functions to the existing pull in other namespaces & it "just worked", but there could certainly be problems with this implementation. Eyes are appreciated.

This PR also includes the "vector as value" support & tests from PR #38 (which I've closed), but I can split these PRs back out if desired.

Fixes #37 , re-posh denistakeda/re-posh#32

Supports solution for denistakeda/re-posh#26

denistakeda commented 4 years ago

Hello @mpdairy . Are you still interested in support this repo?

mpdairy commented 4 years ago

No, I don't really want to support posh. Do you want to? If somebody wants to do a fork or new repo, I'll put a link to it at the top of the README to direct people there. Or I can give access to edit this repo.

denistakeda commented 4 years ago

@mpdairy posh is the critical component for my own re-posh library, which I want to support, so maybe I could support posh either. Let's go for the fork: https://github.com/denistakeda/posh

And thank you for your awesome library!

mpdairy commented 4 years ago

Oh, cool! I didn't know you made re-posh. Well, the fork is in good hands, then. I added a link to your fork.

mpdairy commented 4 years ago

@denistakeda is there a way I can hand over the clojars keys to you so you can take the posh name? it's been so long since I've used clojars...

denistakeda commented 4 years ago

@mpdairy not sure how to change access rights in clojar. But I've already created a new posh artifact.