This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-26
Channels
- # announcements (1)
- # autochrome-github (1)
- # babashka (9)
- # beginners (112)
- # bristol-clojurians (2)
- # calva (26)
- # cider (10)
- # clj-kondo (31)
- # cljs-dev (40)
- # clojure (114)
- # clojure-austin (1)
- # clojure-dev (112)
- # clojure-europe (22)
- # clojure-germany (5)
- # clojure-italy (1)
- # clojure-nl (2)
- # clojure-norway (1)
- # clojure-spec (10)
- # clojure-uk (96)
- # clojurescript (39)
- # core-logic (5)
- # datomic (40)
- # fulcro (34)
- # graphql (17)
- # jobs (3)
- # kaocha (4)
- # leiningen (10)
- # luminus (1)
- # malli (3)
- # meander (44)
- # midje (2)
- # off-topic (40)
- # pathom (5)
- # re-frame (8)
- # reitit (8)
- # ring (3)
- # ring-swagger (4)
- # shadow-cljs (83)
- # spacemacs (96)
- # tools-deps (16)
- # vim (4)
- # xtdb (15)
- # yada (20)
I’ve noticed that when I save a float
e.g 200.9
then it is saved in the database (or at least displayed when I query the value) as 200.899993896484
. Is that a feature and if so then why?
That is just how floats work. They cannot represent every decimal fraction precisely. Use bigdecimal type if you need exact decimal precision
ok, thanks. I guess for things like latitude/longitude, financial values etc. it would be wiser to use bigdecimal. For my simple use cases float has worked fine but the issue I have now is that each time I update an entity which has a float attribute then a change is triggered even if the value does not actually change (`200.9` provided vs 200.08999
in db). I would not mind it but I provide user with an activity log for each entity and now this float value change appears in every transaction. This was unexpected 😕
it's worth mentioning that financial data often works with (64-bit integer) millicents or microcents, to avoid exactly this kind of problem.
it means rounding, but no one cares if they win or lose a rounding to the thousandth of a penny.
For lat/long, I think floats are fine (assuming you aren't doing advanced GPS stuff). Just beware how much precision you actually want when displaying the numbers!
You have two options
1. use double
as the name implies, has 2x the precision of float.
2. Recommended: save all your number in long
format i.e 2009
and when you need to convert it you can always divide and get the value you desire. It also preserves the original value i.e no floating precision errors
Hi, I’m now to datomic and have run into a problem where it feels like there would be some kind of (at least semi-) best practice. I have a set of e
of type foo
in my database, and I want to filter with user input. foo
has a few a
that the user can include in their filter, including cases where you can filter by multiple enumerations of a specific a
, but I’m struggeling to find a good way to do a conditional query. If I make a query that expects all possible a
s as :in
, then (I think) it only matches when all the inputs are valid. I also sort of of feel like this is a place where I should use the pull api, but I have not found a way to run a pull over all e
of foo
.
Hope the explanation makes sense! I’m running datomic free on-prem, so I’ve not look at the client api.
Which number do you want:
1. "All e
of type foo
which have a1
OR a2
?"
2. "All e
of type foo
which have a1
AND a2
?"
2-ish. “All e
of type foo
which might have a1 AND a2 and a..n
depending on user input”
@UUPC4CHEZ your requirement is still ambiguous to me (what does "might have" mean?) but this may help: https://stackoverflow.com/questions/43784258/find-entities-whose-ref-to-many-attribute-contains-all-elements-of-input
That looks interesting, will check it out! In this concrete case, I have the e
:cocktail
that have a
like :ingredient :title :author
, the end-user should be albe to build a search query that can, but does not have to, include filtering by these
yes, is that not correct? all cocktail enties have the same complete set of attributes
{:type :cocktails
:cocktail "Martini"
:ingredients ["Vodka", "vermouth"]
:author "Unknown"}
Yes! and that I can do, but the user should be able to search for cocktails that contain vodka, cream and have the word “russian” in fulltext
(d/q '[:find [(pull ?e [:cocktail/id :cocktail/title :cocktail/recipe :cocktail/preparation :cocktail/ingredients]) ...]
:in $ [?ingredients ...] [?search ...]
:where
[?e :cocktail/ingredients ?ingredients]
[(fulltext $ :cocktail/fulltext ?search) [[?e ?n]]]]
(d/db conn) ingredients fulltext)
Start by building the query up as data using the cond->
macro. I cant help any more right now but I can later tonight.
is how far I got. its a concrete version of only qing two a
, but it fails if any of the two vecs are empty, as it has nothing to match on
ah, cond->
! I don’t think I’ve used that one before. thank you so much for all your help, will look into that!
When generating queries, it's usually more convenient to do it in map form:
{:find [...] :in [...] :where [...]}
For Datomic Cloud is it recommended to have one system per env? (dev, staging, prod)
I ask bc the ion-config.dev
requires an app-name
so not sure how to dynamically configure that based on environment.
I found a related question in forum (https://forum.datomic.com/t/parameterizing-ion-configuration/479) but no conclusive answer from anyone on it, so I’m wondering how people are handling different environments.
you can either have one or multiple systems you can configure your environments with ion environment maps and parameters https://docs.datomic.com/cloud/ions/ions-reference.html#environment-map
say I want multiple systems - so I’d keep the app/system name the same (but give them different environment maps? i didn’t think aws would allow multiple systems with same name but i’ll go ahead and try it
oh maybe the system name has to be different but the app-name
can be the same (i guess that’s why that option exist)