This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-29
Channels
- # announcements (3)
- # babashka (47)
- # beginners (88)
- # calva (17)
- # clj-kondo (8)
- # cljdoc (1)
- # clojars (9)
- # clojure (98)
- # clojure-europe (53)
- # clojure-norway (2)
- # clojure-seattle (1)
- # clojure-uk (5)
- # clojurescript (20)
- # cursive (11)
- # data-oriented-programming (1)
- # data-science (3)
- # datahike (1)
- # datascript (3)
- # events (3)
- # graalvm (5)
- # honeysql (7)
- # hyperfiddle (1)
- # jobs-discuss (10)
- # leiningen (3)
- # malli (16)
- # music (4)
- # nbb (17)
- # off-topic (45)
- # pathom (9)
- # portal (7)
- # releases (1)
- # shadow-cljs (80)
- # sql (15)
- # tools-build (5)
- # xtdb (23)
this looks like what multi is designed for, i haven't used multi, i'm curious where it fails in this case.
Well, I might be wrong, but take a look at this:
(def Something
[:map
[:something string?]
[:type [:enum :a :b]]
[:deep
[:multi {:dispatch :type}
[:a [:map [:depends int?]]]
[:b [:map [:another [:vector int?]]]]]]])
(m/validate
Something
{:something "test"
:type :a
:deep {:depends 3}}) ;=> false
And if I do a really ugly side effect, we can look at what exactly the dispatch
function takes:
(def Something
[:map
[:something string?]
[:type [:enum :a :b]]
[:deep
[:multi {:dispatch (fn [x] (or (println x) :type))} <-------------
[:a [:map [:depends int?]]]
[:b [:map [:another [:vector int?]]]]]]])
(m/validate
Something
{:something "test"
:type :a
:deep {:depends 3}}) ;=> false, but also prints {:depends 3}
I thought about that, but then how would I avoid duplication of the structure?
For example, if I move :multi
to the top of the schema, I would need to make each possibility contain the whole structure right? In this case, :a
would have a schema matching :something
for example. Maybe I can merge in each possibility though, but I was wondering if there was a better solution.
Yep, I guess that's whats you gotta do. You can splice the sub-schemas into smaller chunks for reuse
Depends on what you mean with that. :) We have experimental tool that derives malli schemas from sql table schema
or this (no personal experience): https://github.com/kwrooijen/gungnir
We are already using malli to generate reitit routes from data models, so one thought was to also generate SQL table schemas from same
I suppose any data-driven library like gungnir could work but something that already can do malli->SQL type translation was something I was hoping would be out there somewhere
afaict, this does not do schemas but it seems to have all the parts
it can do table create/drop migrations which should be enough for my purposes, but I'll have to dig into it
i'd be interested to hear your thoughts