This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-24
Channels
- # aleph (1)
- # beginners (43)
- # calva (22)
- # cider (51)
- # clerk (1)
- # clj-kondo (20)
- # clojure (29)
- # clojure-denmark (1)
- # clojure-europe (73)
- # clojure-finland (28)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (12)
- # data-science (2)
- # datomic (51)
- # events (1)
- # fulcro (20)
- # hyperfiddle (28)
- # integrant (6)
- # malli (20)
- # matrix (2)
- # music (1)
- # off-topic (66)
- # reitit (17)
- # releases (5)
- # ring (1)
- # shadow-cljs (31)
- # xtdb (6)
Q: I’m trying to use clojure.core/compare in a query rule for Cloud. I get a strange exception. Deets in thread….
clojure.lang.ExceptionInfo: Unable to resolve symbol: tx-data in this context
cognitect.anomalies/category: :cognitect.anomalies/fault
cognitect.anomalies/message: "Unable to resolve symbol: tx-data in this context"
datomic.client-spi/exception: com.google.common.util.concurrent.UncheckedExecutionException
datomic.client-spi/request-id: "38a341e3-784a-440e-a698-b22a985cc2a5"
datomic.client-spi/root-exception: java.lang.RuntimeException
dbs: [{:database-id "bc6549ca-5e23-47d0-bb13-b185f5c8d9f5",
:t 9034,
:next-t 9035,
:history false}]
Can I see the query?
Thanks but no need. It was an invalid rule that I needed to delete. The only mystery is why it didn't fail in tests but did on cloud
Are you using dev-local
in your tests?
Any updates on a solution for Datomic Cloud users to get some of that sweet, sweet free Datomic goodness? 🙂
Its still coming! We had to clear some hurdles with account limits and AWS Marketplace. Hope to have more news this week.
Its still coming! We had to clear some hurdles with account limits and AWS Marketplace. Hope to have more news this week.
I'm on the newest version of transactor 1.0.6733 with following settings in transactor.properties
ping-host=localhost
ping-port=8080
When I'm trying to curl localhost:8080/health
I'm receiving connection refused.
Logs on transactor side seems okay, though.
2023-05-24 13:31:44.343 INFO default datomic.transactor - {:event :transactor/start, :args {:log-dir "log", :sql-driver-class "org.postgresql.Driver", :ping-host "localhost", :protocol :sql, :rest-alias "sql", :memory-index-max "256m", :port 4334, :memory-index-threshold "32m", :data-dir "./data", :object-cache-max "128m", :host "localhost", :ping-port "8080", :sql-validation-query "select 1", :version "1.0.6733", :encrypt-channel true}, :pid 13268, :tid 13}
I think this is the same issue: https://clojurians.slack.com/archives/C03RZMDSH/p1683025237165599, fix should be in the works
Wow. That was quick and very helpful. Thanks!
Yep! We'll have this fixed in the next release. Discovered too late to get it into 6733.
I'm really struggling with database functions in Datomic. I am specifically looking for a function that will compare datetime stamps of certain entries in the database to today's date. However, in order to debug the error: "Wrong number of args passed to keyword", I have generated the following simple example.
(def three-args
(d/function '{:lang :clojure
:params [x y z]
:code (+ x y z)}))
@(d/transact conn [{:db/doc "Example three-argument function."
:db/ident :three-args
:db/fn three-args}])
From this, I feel that I should be able to then run:
(d/q '[:find ?result
:where
[[:three-args 1 2 3] ?result]] (d/db conn))
And see the result. But I can't. I get that same error above: "Wrong number of args passed to keyword". I take that to mean that the function isn't being recognized. However, when I run:
(d/entity (d/db conn) :three-args)
I get the entity id, and:
(d/invoke (d/db conn) <entity id> 1 2 3)
returns 6, as expected.
Can anyone help?are you using database functions as a deployment method? otherwise you can just call arbitrary functions from within the query in on-prem
Thank you favila! Your first code sample worked, so I have proof of concept, at least. It sounds like calling namespaced functions directly within the query would work for me. I'll be filtering results based on the truthiness of my date checking function, that will work?
predicate forms you can omit the return binding, and truthiness will determine if it unifies
Wow, that's neat. I will try that. Looks like I started out by overengineering 😁 Thank you for your help.
the only caveat I have is that only the first level of the form is inspected for datalog variables
Okay, got it I think. I don't think that will be an issue, but I will see.
the workaround is to adjust the signature of f
to what you need, or to use multiple clauses binding an intermediate
the query runs in the same process and clojure environment as the rest of the peer, so def-ing a new thing and using it from a query requires no ceremony
Yes that works! Thank you so much, this is much, much easier to manage.
Just for completeness sake, comparing dates of entities with today is something you could already do pretty easily. If my memory serves me well; comparison is even implemented more efficiently than using clojure.core/>
:
(d/q '{:find [?e]
:in [$ ?now]
:where [[?e :my-entity/date ?date]]
[(> ?date ?now)]}
db
(Date.))
(although visually, it looks like you are invoking the >
function)
datomic datalog comparison operators work on any datomic attribute type except bytes. They’re not clojure.core/>, which don’t support those (e.g. (< (Date.) (Date.))
throws)
That's a neat idea, too. I will experiment with the simple built-in comparison operators. Thanks Lennart 🙂
Be sure to also check out ‘rules’, which is a way to reuse multiple clauses across queries.
Imo, using the built in stuff, together with rules, should already be powerful enough for the majority of queries you write ^^. Database functions are just a way for you to unlock even more superpowers ;)
Oh rules are cool! I was just thinking, man, wouldn't it be nice if I could build the :where up programatically...
You can! But I would strongly advice to try to get used to writing datomic queries statically (with rules to reuse!).
There are cases to think of to build queries programmatically, to use datomic functions, to do all sorts of magic stuff. But there is nothing as clear as a literal map with datalog clauses and the occasional rule.
(I don’t know how contentious this point is, haha)
Good point. I'm not getting too fancy just yet.