datahike

https://datahike.io/, Join the conversation at https://discord.com/invite/kEBzMvb, history for this channel is available at https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/datahike
whilo 2020-06-13T00:31:06.372600Z

@jrwdunham Neither of these indices is sorted by transaction time, if this is what you need. @konrad.kuehne Can we use one of the history indices for that?

jrwdunham 2020-06-13T17:34:56.373700Z

@whilo so are you saying that I canNOT assume that the following will always be true:

jrwdunham 2020-06-13T17:35:13.373900Z

(= (->> (d/datoms @conn :aevt :db/txInstant)
          reverse
          (map first))
     (->> (d/datoms @conn :aevt :db/txInstant)
          (sort-by (fn [[_ _ tx-time _]] tx-time))
          reverse
          (map first)))  ;; => true

kkuehne 2020-06-15T07:56:45.391800Z

The history index does not care about the time. It only stores entites, that are retracted from the core index either by :db/retract or updating an entity. The order that can satisfy your idea is the transaction id that is monotonically increasing. So with :aevt you should get the datoms in order.

jrwdunham 2020-06-17T18:34:39.392300Z

Thanks @konrad.kuehne.

Aron 2020-06-13T00:34:34.372900Z

🌊

sova-soars-the-sora 2020-06-13T11:37:00.373400Z

🎵

sova-soars-the-sora 2020-06-13T19:36:47.374300Z

Question.... is there a db.type for time?

sova-soars-the-sora 2020-06-13T19:37:11.374500Z

Ah there is! instant 🙂 thnx

sova-soars-the-sora 2020-06-13T23:11:02.375100Z

So I do a query on my database,

(println (d/q '[:find ?m
				 :where
				 [?m :message/kind "chatroom"]
				 [?m :message/title "Beginners"]]
								  @conn))
works great, returns a set
#{[Grammar] [Beginners] [Vocabulary] [にほんご] [Translation]}
But when I try to do an on-the-fly argument from a destructured compojure route, using (str room-name) instead of "Beginners" or something like that... I get no results.
(defn room-handler [room-key ring-req]
...
...
 
(if-let [rk-set 
	
								  (d/q '[:find ?m 
								       :where
								       [?m :message/kind "chatroom"]
								       [?m :message/title (str room-key)]]
								  @conn)]

					 (println "rk-set : " rk-set)
)

sova-soars-the-sora 2020-06-13T23:14:12.375900Z

The invocation (str room-key) ... really room-name... does not give me any results ;x

sova-soars-the-sora 2020-06-13T23:16:13.376400Z

So yeah, rather than hardcoding a string... how can I put a string variable in the query ?

bartuka 2020-06-13T23:24:11.377Z

hi @sova, would be something like this

(d/q '[:find ?m
       :in $ ?room-name
       :where
       [?m :message/kind ?room-name]
       [?m :message/title (str room-key)]]
     @conn
     "chatroom")

sova-soars-the-sora 2020-06-13T23:25:04.377200Z

oh wow

bartuka 2020-06-13T23:26:01.378Z

I might be wrong, but datahike follows the syntax of datascript, therefore there are tons of tutorials here https://github.com/kristianmandrup/datascript-tutorial

bartuka 2020-06-13T23:26:04.378500Z

that might be useful

sova-soars-the-sora 2020-06-13T23:26:39.378700Z

Right on.. Yeah no luck with that line quite yet

sova-soars-the-sora 2020-06-13T23:26:55.379100Z

I thought something like that would work, but I still get an empty result set

sova-soars-the-sora 2020-06-13T23:27:09.379600Z

thanks for the :in $ line... forgot about that from datomic land

sova-soars-the-sora 2020-06-13T23:27:20.380Z

but I am not sure what I'm missing now

bartuka 2020-06-13T23:27:47.380700Z

looking at that piece that I pasted here, the room-key is kind of alien to that query, right?

bartuka 2020-06-13T23:27:59.381300Z

because it is not binded to anyhting

sova-soars-the-sora 2020-06-13T23:28:02.381500Z

When I print the result to console I get

#{[Grammar] [Beginners] [Vocabulary] [にほんご] [Translation]}
notably not in quotes... not a prob?

bartuka 2020-06-13T23:28:10.381700Z

maybe (str ?room-key) works

sova-soars-the-sora 2020-06-13T23:28:44.382200Z

room-key is bound earlier by something else

sova-soars-the-sora 2020-06-13T23:29:04.382700Z

but I don't have the literal ... just a variable that should be equivalent

sova-soars-the-sora 2020-06-13T23:29:18.383200Z

the literal works great, but the variable apparently not so... maybe i am missing something with what happens to this string

bartuka 2020-06-13T23:30:27.383500Z

your first println I would covert as follows

bartuka 2020-06-13T23:30:29.383800Z

(println (d/q '[:find ?m
                :in $ ?kind ?title
                :where
                [?m :message/kind ?kind]
                [?m :message/title ?title]]
              @conn
              "chatroom"
              "Beginners"))

bartuka 2020-06-13T23:30:35.384Z

should yield the same results

bartuka 2020-06-13T23:30:53.384400Z

and how you can change "chatroom" a d "Beginners" by the vars you destructured

sova-soars-the-sora 2020-06-13T23:31:10.384700Z

Oh. that's awesome let me try that

sova-soars-the-sora 2020-06-13T23:32:26.385Z

@iagwanderson you're a genius!

sova-soars-the-sora 2020-06-13T23:33:04.385400Z

two fives way in the air for ya, 5️⃣5️⃣

bartuka 2020-06-13T23:35:36.385600Z

hehe great.

bartuka 2020-06-13T23:35:55.386200Z

depending on how you get these inputs.. there are other forms of binding of inputs

bartuka 2020-06-13T23:35:57.386500Z

(println (d/q '[:find ?m
                :in $ [?kind ?title]
                :where
                [?m :message/kind ?kind]
                [?m :message/title ?title]]
              @conn
              ["chatroom" "Beginners"]))

bartuka 2020-06-13T23:36:02.386800Z

for example, must be valid

bartuka 2020-06-13T23:39:10.387100Z

good read here: https://docs.datomic.com/on-prem/query.html#inputs

bartuka 2020-06-13T23:39:36.387600Z

(idk if all works with datahike, but I would assume they do.)

sova-soars-the-sora 2020-06-13T23:51:39.387800Z

thanks very much

sova-soars-the-sora 2020-06-13T23:51:49.388Z

That helps a lot.