posh icon indicating copy to clipboard operation
posh copied to clipboard

Pull doesn't work with entity ids like 5.036617769192117e+47

Open jpmonettas opened this issue 7 years ago • 3 comments

Steps to reproduce:

(def c (d/create-conn))
(posh/posh! c)

(d/transact! c [[:db/add 1 :person/name "Rich"]
                       [:db/add 5.036617769192117e+47 :person/name "Alex"]])

@(posh/pull c '[:person/name] 1)
;; {:db/id 2, :person/name "Rich"}

@(posh/pull c '[:person/name] 5.036617769192117e+47)
;; nil


;; While it works in datascript
(d/pull @c '[:person/name] 5.036617769192117e+47)
{:person/name "Alex"}

jpmonettas avatar Nov 03 '18 19:11 jpmonettas

Created a PR that fixes this issue (https://github.com/mpdairy/posh/pull/34)

jpmonettas avatar Nov 05 '18 21:11 jpmonettas

While it may be possible to use floating point ids in Datascript, I'm not sure its a good idea. There are likely performance implications, and I'd suspect you should be able to get around this by casting as an int.

metasoarous avatar Nov 06 '18 04:11 metasoarous

I went for a reading and javascript stores everything as double precision floating point numbers, following the IEEE 754 standard. So everything is just 64 bit numbers where the number (the fraction) is stored in bits 0 to 51, the exponent in bits 52 to 62, and the sign in bit 63.

Looking at clojurescript code for "int casting" it just strip decimal places.

I think is a nice property to have posh pull interface to follow datascript pull one.

jpmonettas avatar Nov 06 '18 11:11 jpmonettas