Fork me on GitHub
#datascript
<
2021-02-20
>
Murf02:02:55

Hi everyone! Thanks in advance for help with this datascript query I am trying to run with using string/lower-case within the WHERE clause. window.roamAlphaAPI.q(` [ :find (pull ?block-found [*]) :in $ ?block-string-includes :where [?block-found :block/string ?block-string] [(clojure.string/includes? (clojure.string/lower-case ?block-string) ?block-string-includes)] ] `, 'toggle'); This issue I am having is the following part where I try to turn the block strings to lower case before testing against the “toggle” string with string/includes? Thoughts? Thanks so much! [(clojure.string/includes? (clojure.string/lower-case ?block-string) ?block-string-includes)]

phronmophobic02:02:54

I don't have a repl handy, but I think you have to do it in two steps:

[
 :find (pull ?block-found [*])
 :in $ ?block-string-includes
 :where [?block-found :block/string ?block-string]
 [(clojure.string/lower-case ?block-string) ?lower-block-string]
 [(clojure.string/includes? ?lower-block-string ?block-string-includes)]
 ]

phronmophobic02:02:13

get the lowercase string first and then call includes

Murf03:02:05

Hmmm it’s not working but I’m wondering if the app I’m using does not have the lower-case function available because I’m getting a missing function error. Thanks for your quick help! I’ll try to figure out if that is true.

Josh04:02:38

^^ datascript doesn’t have the lower-case fn by default, but you can pass it in

(d/q
      '[
        :find (pull ?block-found [*])
        :in $ ?lower-case ?block-string-includes
        :where
        [?block-found :block/string ?block-string]
        [(?lower-case ?block-string) ?lower-block-string]
        [(clojure.string/includes? ?lower-block-string ?block-string-includes)]
        ]
      @conn
      clojure.string/lower-case
      "toggle")
Here’s the list of built ins https://github.com/tonsky/datascript/blob/def78a2079230b2d58dd2555ab100a03233f3e49/src/datascript/query.cljc#L194

Murf07:02:40

@U018E92R0TY thanks! The app I am working on this for is pretty cool. You should try it ;) :rolling_on_the_floor_laughing:

teodorlu10:02:14

@U015C84JNLQ what are you working on? I'm curious about the Roam extension ecosystem.

Murf10:02:10

@U3X7174KS honestly this was just for building a simple wrapper for the read api so that I can have case insensitivity searches of all block that contain “xyz”

teodorlu10:02:36

@U015C84JNLQ Nice. How are you using it? From inside your Roam graph? I haven't had the time to look into Roam extensibility, but I suspect I should.

Murf20:02:47

You can do roam/js which allows you to run custom js straight from roam. I was just testing a query in chrome dev tools console.

👍 3
Murf21:02:25

@U018E92R0TY so that should work for {{roam/render}} right? But what I’m trying to do is with roam/js using the alpha api datascript queries. Am I able to pass other clojure functions in with the window.roamAlphaAPI.q through roam/js? Thanks.

👍 3
Josh02:02:19

It works for roam/render. for js I think you’d have to write a toLowerCase function and pass that in, but haven’t tested passing function in in js yet

👍 3