what is the min and max for :int?
The minimum and maximum accepted values
(m/validate (m/schema [:int {:min 1 :max 5}])
3)
;; => true
(m/validate (m/schema [:int {:min 1 :max 5}])
6)
;; => false
or are you asking if theres a point where there's integer overflow/underflow?
yes, Samuel, thank you
Oh, sorry then I assumed it was for the options
I'm not sure how validation is done, or if it's backed by a data type. Integer.MAX_VALUE = 2147483647 for java, but:
(malli.core/validate :int 2147483647) -> true
(malli.core/validate :int 2147483648) -> trueI know clojure.lang.BigInt does not pass but java.lang.Long does. I haven't delved into it
it doesnt look like it's simply about looking for digits because
> (malli.core/validate :int 999999999999999999)
true
> (malli.core/validate :int 9999999999999999999)
falseI assume this is because
(type 999999999999999999)
;; => java.lang.Long
(type 9999999999999999999)
;; => clojure.lang.BigInt
yes, thank you! so it looks like there is an actual type backing the validation after all:
> (. Long MAX_VALUE)
9223372036854775807
> (malli.core/validate :int 9223372036854775807)
true
> (malli.core/validate :int 9223372036854775808)
false
> (. Long MIN_VALUE)
-9223372036854775808
> (malli.core/validate :int -9223372036854775808)
true
> (malli.core/validate :int -9223372036854775809)
falseclojure prefers long for primitives, so this matches that
https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L743
:int matches clojure.core/int?
examples of its behaviour here: https://clojuredocs.org/clojure.core/int_q
I am writing complex SQL queries including with json aggregates in order to optimize some pathom resolvers Problem: pathom resolvers encourages the use of qualified keywords, and when you start having array_agg and json_agg and alias things around in becomes tedious to have a jdbc builder-fn that works as you want I have been fiddling with Malli to solve this issue and came up with a solution that seems okay, happy to hear any feedback / ideas to improve or alternatives. Here's what I do:
(malli/decode
[:map {:map/rename-keys {:address :user/address}}
[:id string?]
[:tags [:set keyword?]]
[:user/address
[:vector
[:map
{:map/rename-keys {:street :user/street}}
[:user/street string?]
[:city string?]
[:zip int?]
[:lonlat [:tuple double? double?]]]]]]
{:id "Lillan",
:tags ["coffee" "artesan" "garden"],
:address [{:street "Ahlmanintie 29"
:city "Tampere"
:zip 33100
:lonlat [61.4858322 23.7854658]}
{:street "Ahlmanintie 291"
:city "Tampere"
:zip 33100
:lonlat [61.4858322 23.7854658]}]}
(mt/transformer
{:decoders
{:map
{:compile (fn [schema _]
(when-let [mapping (:map/rename-keys (malli/properties schema))]
(fn [value]
(clojure.set/rename-keys value mapping))))}}}))
Essentially I am using a custom transformers to rename specific keys in my maps
So in practice I am:
• writing a schema of what I expect to come out of my resolver
• adding properties to define the key-mappings