Fork me on GitHub
#biff
<
2022-11-28
>
2FO20:11:15

Howdy all, Coding novice here, after some data modeling feedback. Let's say I'm building a site that lists gift shops and the currencies they accept. I could store each currency code as a string in the store's document:

:store/id uuid
:store [:map {:closed true
[:store/currency [:vector  [:string]]]
...
but I imagine that could get messy (multiple opportunities for an admin to mistype a code etc). So my question is, where the data is both finite and known e.g currency codes. Is it better to create a new document and reference it by id.
:currency/id uuid
   :currency [:map {:closed true}
              [:currency/country :string]
              [:currency/code    :string]]

   :store/id uuid
   :store [:map {:closed true}
           [:store/currency  [:vector [:currency/id]]
           [:store/name                :string]]]  
:thinking_face:

Jacob O'Bryant23:11:37

Malli has an enum type that would work nicely. e.g. update first example to :store/currency [:enum :usd :eur ...]. If you're only dealing with a small total number of currencies, you could do that as-is. If you want to support all the currency codes, you could define them in a separate var, e.g. (def currencies [:usd :eur ...]) and then do :store/currency (into [:enum] currencies).

2FO00:11:30

Super useful, thank you. Takes care of the follow up question I had WRT handling small vs large property lists

👌 1
2FO16:11:44

If I wanted to bind the currency codes to their respective country names as strings:

(def currencies {:usd "United States"
...})
Is this a sound approach:
:store/currency (into [:enum] (keys currencies)) 
With a view to rendering the countries name next to it's currency code in the DOM.

Jacob O'Bryant16:11:39

yes, that's a great way to do it

🙏 1