Fork me on GitHub
#datomic
<
2020-03-19
>
Vishal Gautam16:03:58

Hi, is there a simpler way to solve this.

(d/q '[:find (pull ?fid [*])
       :in $ ?email ?follow-id ?follower-email
       :where
       [?uid :user/email ?email]
       [?uid :user/following ?follow-id]
       [?fid :user/email ?follower-email]]
     (d/db conn)
     ""
     [:user/email ""]
     "")

favila17:03:43

Simpler in what way?

favila17:03:49

Solve what?

Vishal Gautam17:03:23

So I have a user-id and a follower-id, I want to fetch all information of the follower if the user is following

Vishal Gautam17:03:05

I managed to simplify down to this function

(defn get-follower
  "Fetch all the User followers information"
  [db user-email follower-email]
  (->> (d/q '[:find (pull ?follow-id [*])
              :in $ ?email ?follow-id
              :where
              [?uid :user/email ?email]
              [?uid :user/following ?follow-id]]
            db
            user-email
            [:user/email follower-email])
       ffirst))

Vishal Gautam17:03:40

Please disregard this post 🙂

zilti17:03:31

Is there some place that helps me decide on which storage engine I should use for Datomic?

zilti17:03:34

This tells me the how, not really the why I should decide for a particular one. I guess PostgreSQL is the "standard"? And, will Cassandra give me more performance, or PostgreSQL?

favila17:03:40

datomic uses storage as a generic key-value store, with only a few keys needing atomic updates

favila17:03:23

the particulars of the storage systems installs themselves are going to dominate more than which technology you use

favila17:03:53

(and if you are on aws, dynamo is likely the “standard” choice)

zilti17:03:45

It would be on premise for us, we're a startup and it is the best for us to keep the data on our own servers. Okay, so there isn't any particular difference as far as performance goes, good to know. Thanks!

zilti17:03:43

(that said, we'll have to look how we proceed after a year with this new product of ours. Over $400/month for on-premise is a hefty price tag for a startup)

favila18:03:51

IMO you should prefer whatever you are most familiar with

favila18:03:02

you will already know how to resize, scale and and tune it if it needs

👍 4
Vishal Gautam17:03:12

@favila Is there a way to pass pattern as an argument, to determind what items you want to fetch

(defn fetch-articles-by-tags
  [conn tags pattern]
  (d/q '[:find (pull ?aid ?pattern)
         :in $ ?tags ?pattern
         :where
         [?aid :article/tagList ?tags]]
       (d/db conn)
       tags
       pattern))

Vishal Gautam17:03:20

this code for example does not work

favila17:03:53

(defn fetch-articles-by-tags
  [conn tags pattern]
  (d/q '[:find (pull ?aid pattern)
         :in $ ?tags pattern
         :where
         [?aid :article/tagList ?tags]]
       (d/db conn)
       tags
       pattern))

🎉 4
Vishal Gautam17:03:55

Why didnt mine work, does adding ? make a huge difference?

favila18:03:07

normally aggregation functions in find can receive only one bound value

Vishal Gautam18:03:30

You are the best 😄

favila18:03:33

this is a special-case. by omitting ? you are signaling that this is not a binding; then it inlines that into the pull

favila18:03:58

this wasn’t even supported in the beginning--this feature got added at some point without my noticing

Vishal Gautam18:03:41

Right, definitely a gotcha for someone learning this technology