This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-31
Channels
- # announcements (6)
- # babashka (40)
- # beginners (6)
- # calva (1)
- # cider (1)
- # clerk (43)
- # clj-kondo (3)
- # clojure (93)
- # clojure-denver (8)
- # clojure-europe (52)
- # clojure-norway (20)
- # clojure-sweden (7)
- # community-development (5)
- # datascript (15)
- # datomic (30)
- # emacs (24)
- # events (15)
- # fulcro (23)
- # graalvm (12)
- # gratitude (1)
- # helix (4)
- # honeysql (4)
- # hoplon (39)
- # hyperfiddle (7)
- # introduce-yourself (1)
- # jobs (1)
- # jobs-discuss (26)
- # lambdaisland (3)
- # lsp (6)
- # matcher-combinators (2)
- # matrix (5)
- # meander (39)
- # nrepl (4)
- # nyc (1)
- # off-topic (5)
- # portal (73)
- # practicalli (1)
- # re-frame (2)
- # reitit (22)
- # releases (1)
- # remote-jobs (4)
- # shadow-cljs (5)
- # sql (17)
- # testing (1)
- # tools-deps (15)
I was wondering if somebody could help me with a query to select a subgraph. If I have the following data:
{:user/id "foo"}
{:user/id "bar"}
{:user/id "baz"}
{:relationship/from "foo"
:relationship/to "bar"
:relationship/type :son}
{:relationship/from "bar"
:relationship/to "baz"
:relationship/type :son}
How could I do a recursive traversal to get all three records given user id foo
generally you approach this with a recursive rule with two implementations: the “root/self” case, which returns the node you are on; and a “descend” case, which advances to the descendant node. E.g.:
[;; root and node case
[(children-and-self [?eldest-parent] ?user)
[(identity ?eldest-parent) ?user]]
;; recursive descent case
[(children-and-self [?eldest-parent] ?user)
[?relationship :relationship/from ?eldest-parent]
[?relationship :relationship/type :son]
[?relationship :relationship/to ?descendant]
(children-and-self ?descandant ?user)]]
this is the basic template; you can modify it to e.g. include a generation counter, a parameterizable relationship type, etc
ah yeah, the relationship is via a ref, and thanks that looks like what I'm looking for
oh could you give an example of the whole query, I'm having a bit of trouble using the rule, sorry complete newb with the syntax 🙂
(def rules '[;; root and node case
[(children-and-self [?eldest-parent] ?user)
[(identity ?eldest-parent) ?user]]
;; recursive descent case
[(children-and-self [?eldest-parent] ?user)
[?relationship :relationship/from ?eldest-parent]
[?relationship :relationship/type :son]
[?relationship :relationship/to ?descendant]
(children-and-self ?descandant ?user)]])
(def query '[:find ?user :in $ % ?parent :where (children-and-self ?parent ?user)])
(d/q query db rules parent-id)
Just wanted to stop in and tell @U09R86PA4 thanks for this tutorial. Spent the last couple of hours lost on this. Was about to give up until I saw your example. I didn't realize that you needed a var to bind the output to (`?user` in this case). (Or at least that's my interpretation of what I was doing wrong.)
basically what I'd like to do is to select {:user/id "foo"}
then look up all the relationships with :relationship/from "foo"
, and then recursively do that for each :relationship/to
entity.
I'm playing around with https://github.com/carrete/datopro-mic. This is just an experiment and might disappear at some point, but regardless before I get too far I want to make sure I'm not violating a license, trademark, or similar. The repo name has been mangled, and the README contains a disclaimer about no connection to Cognitect. The binaries have not been committed to the repo. They're downloaded on-demand. I haven't applied a license to my work so far. What's there now should be considered in the public domain. At some point though, if I do spend more time on this, I might add my own copyright and license to what I've done and have committed to the repo. Can anyone see a problem with this? Thanks
Apache 2.0. Binaries are free and distributable. No issues here! I would love to hear of your experience getting pro to run on fly! I know of only one other user trying to do the same and I never heard how it all panned out.
> No issues here! Sweet! Thanks for the confirmation, Jaret Datomic hasn't caused me any problems. I was running on-prem in AWS in previous project, and it was always rock solid. Getting up-to-speed on http://fly.io was trickier than I thought it would be though. Some things can't be defined in fly.toml, like vm size, so it's an unexpected mix of functional and imperative. Services are assumed to be exposed publicly. To create a private service, the service section is omitted and only a health check section is needed which was not obvious. Additionally, every service is assigned a name on the mesh network, and is accessible to every other service under the same org. So orgs are more like environments, I guess? That said everything has been pretty stable, and even though I'm the only one who has been playing around with this, I have yet to be billed for anything
@U0P7ZBZCK have you deploy the transactor? what is your instance memory? I have trouble to deploy the transactor on fly because not enough memory.
Hey @UHZPYLPU1, This is something I thought of later on in response to @U1QJACBUM’s inquiry above. I https://github.com/carrete/datopro-mic/commit/61bd71d6721403b748973189b63be42281db6263#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R158 which is probably more than necessary but it got me going. It would be nice to have a set of recommended settings for the transactor and peer servers optimized for minimal resource usage while still being reasonably useful (so more than minimum requirements, I assume)
@U0P7ZBZCK in your image you copy the whole datomic-pro folder?
https://docs.datomic.com/pro/operation/capacity.html#transactor-memory We recommend production settings at 4g of RAM. 1g for dev use. The capacity docs I linked give more information on what the transactor needs memory for and what "enough" memory means interms of needing to cover the memory-index-max and object-cache-max summed + headroom. YMMV and be heavily dependent on transaction throughput.
Correct. One container image contains the transactor, peer server, and console. I had a prior version that was much more efficient in this regard, but I ended up thinking that was too much effort for too little benefit. I don't have a strong opinion one way or the other. I thought about putting the jars on a volume too, but decided against for the same reason
Thanks @U1QJACBUM!
@U0P7ZBZCK how do I get your repo to make apps on http://Fly.io and deploy them? I see a bunch of commands here but not sure when to run what: https://github.com/carrete/datopro-mic/blob/main/Makefile
@U051SPP9Z I just pushed up an update to the README. Please let me know if you encounter any problems
This has been updated to be easier to work with. Please see the updated README for details. https://github.com/carrete/datopro-mic
FYI, I've updated this to use Postgres as the storage backend. Please see the "postgres" branch. Given that my original goal with this was to make it easy to run Datomic Pro locally or on http://Fly.io for development purposes only, I'm not sure I see much of a benefit of adding Postgres. For this reason, I doubt I'll merge the postgres branch into main
hey 👋 I noticed that the q
docstring https://docs.datomic.com/pro/clojure/index.html#datomic.api/q is linking to a 404: https://docs.datomic.com/pro/query.html#find-specifications
https://docs.datomic.com/pro/query/query.html#find-specifications Appears to be the correct link