Fork me on GitHub
#xtdb
<
2020-09-24
>
victorb08:09:59

Hello everyone! Is there some more documentation/examples on how the EQL projection stuff works? Trying to figure out but doesn't seem it's enough for my brain with the three examples from the docs website. Particularly interested in the reverse joins

jarohen09:09:01

We've kept as much to EQL as possible, so their docs are a good reference for Crux as well - https://edn-query-language.org/eql/1.0.0/what-is-eql.html Crux's 'project' is currently in alpha, we've not added union or recursive queries as yet. Reverse joins aren't part of EQL - these are done by prefixing the attribute by an underscore

๐Ÿ‘ 3
jarohen09:09:35

so, if I had two documents with a relationship between them (A referring to B, say) but I start my projection at B, I need to use the underscore-prefixed attribute to refer back to A

{:crux.db/id :a, :refers-to :b}
{:crux.db/id :b}
(crux/q db
        '{:find [(eql/project ?b [:crux.db/id {:_refers-to [:crux.db/id]}])]
          :where [[?b :crux.db/id :b]]})

jarohen09:09:59

#{[{:crux.db/id :b, 
    :_refers-to [#:crux.db{:id :a}]}]}

victorb09:09:07

Yup, thanks! I got it all working as expected now, I think

simple_smile 3
victorb09:09:29

ended up with something like this:

(crux/submit-tx @crux-node [[:crux.tx/put {:crux.db/id :website-1
                                             :website/id :website-1
                                             :website/name "My Website"
                                             :user/email "[email protected]"}]
                              [:crux.tx/put {:crux.db/id :page-1
                                             :page/id :page-1
                                             :page/website_id :website-1
                                             :page/name "First page"}]
                              [:crux.tx/put {:crux.db/id :page-2
                                             :page/id :page-2
                                             :page/website_id :website-1
                                             :page/name "Second page"}]])
  (pprint
    (query '{:find [(eql/project ?website [:website/name {:page/_website_id [:page/id :page/name]}])]
             :where [[?website :website/id ?id]]}))

victorb08:09:49

Gah, as is tradition. Been trying to understand it since about a day ago. Five minutes after posting the message, my assumptions finally matches how it actually works... :face_palm:

jarohen09:09:11

often the way ๐Ÿ™‚

๐Ÿ˜ 3
malcolmsparks09:09:17

You could look in query_test.clj too.

victorb09:09:15

oooh, query_test.clj is really helpful, wish I found that earlier! Would be nice to have it linked from the docs website surely ๐Ÿ™‚

jarohen09:09:30

over time we'd migrating more and more examples from that one into the docs, certainly ๐Ÿ™‚

malcolmsparks09:09:02

There's many places where the tests will be more comprehensive than the docs, we are trying our best to keep everything updated. However, peering into the test code is a good achievement to unlock ๐Ÿ™‚

victorb09:09:24

yeah, keeping docs and tests in sync is always hard. https://github.com/seancorfield/readme is a interesting project trying to integrate the two better, maybe some inspiration could be had with that

motform11:09:04

Quick question, what is the story with storing blobs in Crux? I have looked around but not really found a good answers.

refset11:09:33

Hi, Crux doesn't store blobs natively today. Though we may yet add support. You could either wrap blobs in java objects and store them as serialised values, or use base64 What is your use-case? Is it cryptographic keys by any chance?

motform11:09:11

No, Iโ€™m making a small thing thatโ€™s going to allow users to record and store audio. But I think it is of such a small scale that I could just chuck them into the file system.

victorb11:09:27

Having the same use case (storing images and vectors). Ended up writing the bytes to disk and storing the path instead

๐Ÿ‘ 3
victorb11:09:02

Although, the filename is the cryptographic hash of the content, so could be looked up from other hosts as well if needed

motform11:09:36

That sounds like the best solution, at least at this scale. thanks for the prompt replies!

๐Ÿ™ 3
ordnungswidrig13:09:31

This method has served me well in the past. The only thing you need to remember is to implement some kind of garbage collection, unless you donโ€™t mind your S3 bill. ๐Ÿ˜›

nivekuil20:09:32

crux doesn't have a built-in way of doing something like datomic's reified transactions as shown at the bottom of this section: https://vvvvalvalval.github.io/posts/2018-11-12-datomic-event-sourcing-without-the-hassle.html#processing_events_with_datomic right?

refset11:09:29

Hi, correct there's nothing built-in for this, but you can create a transaction function to suit your exact requirements. e.g. https://gist.github.com/refset/a00be06443bc03ccc84a2874af3cdb8a#file-txfns-clj-L1-L8

๐Ÿ‘ 3
nivekuil20:09:54

also, I noticed that in the last release notes mention of slack has been dropped.. I suppose you folks strongly prefer to use the zulip at this point?

refset11:09:06

We'll always be happy to chat here ๐Ÿ™‚ Clojurians Slack is a wonderful thing! Although for general "support" purposes the lack of proper threading and searchable history makes Slack pretty frustrating to work with. Also we're keen to not turn-off our potential non-Clojure users (esp. Java / Kotlin) by appearing to prioritise help for Clojure users

flefik21:09:04

my crux jdbc connection broke when bumping from 20.05 to 20.09. A bug perhaps?

(crux/start-node {:crux.node/topology '[crux.jdbc/topology]
                     :crux.jdbc/dbtype   "postgresql"
                     :crux.jdbc/dbname   (:dbname config)
                     :crux.jdbc/host     (:host config)
                     :crux.jdbc/user     (:user config)
                     :crux.jdbc/port     (:port config)
                     :crux.jdbc/password (:password config)
                     })))

flefik21:09:43

Execution error (IllegalArgumentException) at crux.system/opts-reducer$f (system.clj:127).
Unexpected config option 15432

flefik21:09:42

It's complaining about the port option (:port config) ;; => 15432

nivekuil21:09:30

especially

;; before {:crux.node/topology '[crux.jdbc/topology]  :crux.jdbc/dbtype "postgresql"  :crux.jdbc/dbname "cruxdb"  :crux.jdbc/host "<host>"  :crux.jdbc/user "<user>"  :crux.jdbc/password "<password>"}  ;; after - shared connection pool {::jdbc/connection-pool {:dialect 'crux.jdbc.psql/->dialect                          :db-spec {:dbname "cruxdb"                                    :host "<host>"                                    :user "<user>"                                    :password "<password>"}}  :crux/tx-log {:crux/module `crux.jdbc/->tx-log, :connection-pool ::jdbc/connection-pool}  :crux/document-store {:crux/module `crux.jdbc/->document-store, :connection-pool ::jdbc/connection-pool}  :crux/index-store {...}}

๐Ÿ™ 3
flefik21:09:52

thanks!

โž• 3