Fork me on GitHub
#datahike
<
2020-06-13
>
whilo00:06:06

@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?

sova-soars-the-sora19:06:47

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

sova-soars-the-sora19:06:11

Ah there is! instant 🙂 thnx

sova-soars-the-sora23:06:02

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-sora23:06:12

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

sova-soars-the-sora23:06:13

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

bartuka23:06:11

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")

bartuka23:06:01

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

bartuka23:06:04

that might be useful

sova-soars-the-sora23:06:39

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

sova-soars-the-sora23:06:55

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

sova-soars-the-sora23:06:09

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

sova-soars-the-sora23:06:20

but I am not sure what I'm missing now

bartuka23:06:47

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

bartuka23:06:59

because it is not binded to anyhting

sova-soars-the-sora23:06:02

When I print the result to console I get

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

bartuka23:06:10

maybe (str ?room-key) works

sova-soars-the-sora23:06:44

room-key is bound earlier by something else

sova-soars-the-sora23:06:04

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

sova-soars-the-sora23:06:18

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

bartuka23:06:27

your first println I would covert as follows

bartuka23:06:29

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

bartuka23:06:35

should yield the same results

bartuka23:06:53

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

sova-soars-the-sora23:06:10

Oh. that's awesome let me try that

sova-soars-the-sora23:06:04

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

bartuka23:06:36

hehe great.

bartuka23:06:55

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

bartuka23:06:57

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

bartuka23:06:02

for example, must be valid

bartuka23:06:36

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