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?

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?

sova19:06:47

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

sova19:06:11

Ah there is! instant 🙂 thnx

sova23: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)
)

sova23:06:12

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

sova23:06:13

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

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

iagwanderson23: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

iagwanderson23:06:04

that might be useful

sova23:06:39

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

sova23:06:55

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

sova23:06:09

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

sova23:06:20

but I am not sure what I'm missing now

iagwanderson23:06:47

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

iagwanderson23:06:59

because it is not binded to anyhting

sova23:06:02

When I print the result to console I get

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

iagwanderson23:06:10

maybe (str ?room-key) works

sova23:06:44

room-key is bound earlier by something else

sova23:06:04

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

sova23:06:18

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

iagwanderson23:06:27

your first println I would covert as follows

iagwanderson23:06:29

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

iagwanderson23:06:35

should yield the same results

iagwanderson23:06:53

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

sova23:06:10

Oh. that's awesome let me try that

sova23:06:26

@iagwanderson you're a genius!

sova23:06:04

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

iagwanderson23:06:55

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

iagwanderson23:06:57

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

iagwanderson23:06:02

for example, must be valid

iagwanderson23:06:36

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

sova23:06:39

thanks very much

sova23:06:49

That helps a lot.