This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-18
Channels
- # beginners (17)
- # calva (1)
- # clara (1)
- # cljs-dev (12)
- # clojure (151)
- # clojure-france (11)
- # clojure-uk (6)
- # conjure (4)
- # datomic (32)
- # duct (42)
- # emacs (2)
- # fulcro (20)
- # lambdaisland (4)
- # malli (5)
- # meander (32)
- # pathom (8)
- # reagent (1)
- # reitit (7)
- # shadow-cljs (2)
- # sql (6)
- # tools-deps (2)
- # vim (17)
- # xtdb (1)
I fail to connect to my freshly set up datomic-pro. I get this error, which seems to be the usual one:
Datomic itself seems to have started fine:
System started datomic:sql://<DB-NAME>?jdbc:
In the transactor config, I've set protocol to sql, host to 127.0.0.1 and port to 4334. I've added the license key and set the sql-url, -user, -password and -driver-class.
Is the peer also on localhost? If not you need to change transactor host= to something the peer can reach
Transactors bind to host then write host and alt-host to storage. Peers then read those out of storage and attempt to connect to either of them. So you need host and/or alt-host to be routeable hosts or ips peers can connect to
Noobie question: Is it possible to create a Datomic schema where a value has an expected type of any, or at least a union type? I'd like a value to be either a string, integer, or float.
I am not a datomic expert, but you could store your value as symbol? Otherwise you could save it as a ref and create the correct entity for each value (probability it has a lot memory disadvantage, but it would solve your problem).
For cardinality one attributes, you can do a kind of tagged union thing. Make your polymorphic attr with a ref type; it’s value should be the attr with a specific variant attr
For cardinality many, if your type options are only scalar types maybe you can use fixed length heterogeneous tuples where only one value is non nil
Where I landed is I created three different entity schemas — one with a string attr, one with a float attr, one with an integer attr — then created an OR rule that will get the appropriate attribute value based on the entity, so that, given one of the three kinds of entities, I can uniformly access the value. It’s a little like a union type, and appears to work nicely.
You have to check three indexes, and you have to ensure only one is asserted at a time
Unless you mean there’s some other value on the entity that tells you which one it is? “One of the three kinds of entities” I’m not sure what that means
Let put more flesh on these bones.
;; Schema
#:db{:ident :foo-string/val
:valueType :db.type/string
:cardinality :db.cardinality/one}
#:db{:ident :foo-float/val
:valueType :db.type/float
:cardinality :db.cardinality/one}
#:db{:ident :foo-integer/val
:valueType :db.type/long
:cardinality :db.cardinality/one}
;; Rules
[[(val ?e ?v)
[?e :foo-string/val ?v]]
[(val ?e ?v)
[?e :foo-float/val ?v]]
[(val ?e ?v)
[?e :foo-integer/val ?v]]]
I'm also interested in learning more about profiling the performance of my rule — are you familiar with any recs or literature on how to do that?
3 index lookups and its structurally possible to have more than one asserted on same entity
(In my case I’m not very concerned about the possibility of more than one assertion on the entity, but I am concerned about slowness.)