Fork me on GitHub
#datomic
<
2020-03-26
>
Sven00:03:00

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?

favila01:03:51

That is just how floats work. They cannot represent every decimal fraction precisely. Use bigdecimal type if you need exact decimal precision

Sven01:03:57

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 😕

Braden Shepherdson02:03:44

it's worth mentioning that financial data often works with (64-bit integer) millicents or microcents, to avoid exactly this kind of problem.

👍 4
Braden Shepherdson02:03:03

it means rounding, but no one cares if they win or lose a rounding to the thousandth of a penny.

mavbozo06:03:30

i've faced problems with purchase amount in mysql because it was stored as float

teodorlu11:03:30

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!

Vishal Gautam16:03:28

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

motform11:03:23

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 as 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.

motform11:03:31

Hope the explanation makes sense! I’m running datomic free on-prem, so I’ve not look at the client api.

Joe Lane14:03:27

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 ?"

motform14:03:08

2-ish. “All e of type foo which might have a1 AND a2 and a..n depending on user input”

motform14:03:44

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

Joe Lane14:03:35

How many a exist ( or will exist? )

motform14:03:30

a known amount, all :cocktail have the same data in this set

Joe Lane14:03:45

Are you referring to a as an attribute for the entity?

motform14:03:33

yes, is that not correct? all cocktail enties have the same complete set of attributes

Joe Lane14:03:32

{:type :cocktails
 :cocktail "Martini"
 :ingredients ["Vodka", "vermouth"]
 :author "Unknown"}

Joe Lane14:03:13

And you want the ability to search for drinks which take Vodka

motform14:03:04

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

motform14:03:40

(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)

Joe Lane14:03:49

Start by building the query up as data using the cond-> macro. I cant help any more right now but I can later tonight.

👍 4
motform14:03:16

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

motform14:03:48

ah, cond->! I don’t think I’ve used that one before. thank you so much for all your help, will look into that!

val_waeselynck14:03:25

When generating queries, it's usually more convenient to do it in map form:

{:find [...] :in [...] :where [...]}

motform14:03:44

oh, can you pass maps to q? that makes life a lot easier lol

Aleed16:03:23

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.

marshall17:03:49

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

Aleed18:03:38

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

Aleed18:03:43

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)

Aleed18:03:29

that clarifies a lot, thanks

joshkh19:03:05

can i call d/with on the results of calling d/with ?

val_waeselynck19:03:43

Yes, and a lot of power follows from that :)

🙏 4
wizard 4
datomic 4
4
4
joshkh19:03:37

right. i'm sure i've done this before, but i'm drawing a blank. d/with requires a d/with-db conn, but the result of d/with doesn't return a connection. does it?

joshkh19:03:22

oh of course. :db-after is already with-db'ed.

johnj21:03:07

Does the peer uses connection pooling when using a SQL database?