This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-14
Channels
- # aleph (1)
- # aws (3)
- # beginners (75)
- # boot (1)
- # bristol-clojurians (2)
- # clj-kondo (18)
- # cljs-dev (5)
- # cljsrn (10)
- # clojure (62)
- # clojure-dev (15)
- # clojure-europe (3)
- # clojure-india (2)
- # clojure-italy (9)
- # clojure-madison (1)
- # clojure-nl (9)
- # clojure-norway (9)
- # clojure-spec (11)
- # clojure-uk (206)
- # clojurescript (30)
- # copenhagen-clojurians (1)
- # data-science (1)
- # datascript (2)
- # datomic (27)
- # emacs (1)
- # events (1)
- # fulcro (12)
- # gorilla (1)
- # jobs (2)
- # kaocha (2)
- # leiningen (4)
- # lumo (7)
- # malli (1)
- # off-topic (2)
- # pathom (14)
- # pedestal (5)
- # quil (3)
- # re-frame (8)
- # reitit (3)
- # remote-jobs (16)
- # ring-swagger (1)
- # shadow-cljs (70)
- # tools-deps (7)
- # vim (5)
- # vrac (1)
I'm looking at spec'ing Datomic data structures (e.g., data in tx-data
and results from queries and pull). For the most part, it's pretty straightforward. One wrinkle is references: the value can be a variety of things, such as a long
(the entity id), any of the different lookup-ref forms, or a map of the referenced entity attributes (e.g., in result sets). All will have the same key. In some contexts I'll definitely want a lookup-ref as opposed to a map (e.g., in a transaction where I want to reference an extant entity), so I'm wondering how to handle validation. Any ideas on approaches?
Use spec2/union. Look for prior art on folks already attempting to spec datomic. Identify which scenarios you "definitely want a lookup-ref as opposed to a map" and define a different select / union for those scenarios (luckily, you seem to already have identified them!). For speccing the tx-data, just follow the grammar on the docs page.
Cheers! is there a reference for union? I don't see it immediately at hand on the wiki Looks like it's on the schema/select page.
unions are probably going to go away or change name, so don't lean on that too hard
That being the case, would you have a pointer towards another approach I might take? Where in some contexts, I want tighter validation than others for the same spec/key?
is there some reason not to s/or all the options?
and then s/and in more constrained predicates when needed?
and separately, are these tighter constraints actually helping you enough to be worth the trouble?
Say I'm using Datomic-like data structures in my application, as Datomic is my primary data store and they're nice data structures to do business logic on anyway. I have a new (not yet persisted) entity that contains a reference to another, (should-be-pre-existing) entity. If I want to transact that data, I'll use a look-up ref (which will guarantee failure if that entity doesn't already exist, which is what I want). If I use a map as that reference, it will create that entity (which is not what I want). I can create a spec that accepts a map or a lookup-ref as valid values for the key, but in the tx-data case, I only want the lookup-ref version, not the map version. Am I thinking about this wrong?
Stepping back, datomic transactions are a DSL. does it make sense to spec it as a DSL, or to spec your particular use of it?
but if you try to spec the DSL at a more semantic level, you may conflict with the βreadβ view of those keys (i.e. what you get from d/pull, etc)
sometimes, it's just not worth getting down to that level of specificity
or if you need to, consider making a new DSL for your transactions, and speccing that instead
@U09R86PA4 that makes sense. Cheers.
Stronger than that. @U09R86PA4 that really clarifying. doubleplussgood
Is it possible to use classpath functions with an in-memory database created with the peer library?