Fork me on GitHub
#datascript
<
2020-11-30
>
lambdam18:11:26

Hello, I'm trying to take a subset of information from Datomic and use it with Datascript. The entities have this shape:

{:db/id 17592186048456
 :user/email ""
 :user/birthdate #inst "1997-07-07T10:00:00.000-00:00"
 :user/lastname "BAR"
 :user/firstname "Foo"}
When I transact this data I have the following error Highest supported entity id is 2147483647, got 17592186048456 . I played with Datascript and Datomic:
(->> datomic-db
     (d/q '[:find ?user .
            :where [?user :user/email]])
     type)
;; => java.lang.Long

(as-> (ds/create-conn) <>
  (ds/transact! <>
                [{:db/id "temp-id"
                  :user/email ""
                  :user/birthdate #inst "1997-07-07T10:00:00.000-00:00"
                  :user/lastname "BAR"
                  :user/firstname "Foo"}])
  (:db-after <>)
  (ds/q '[:find ?e .
          :where
          [?e :user/email]]
        <>)
  (type <>))
;; => java.lang.Integer

lambdam18:11:12

Is there a particular reason for having different types for db ids? Is there a way to tell Datascript to use Long instead of Integer? ping @tonsky Thanks

pithyless19:11:28

@dam this is a limitation that DataScript imposes, because (a) JS is limited to 32-bit signed integers, and (b) even that is further split into two buckets: one range for datom-ids and second range for transaction-ids. See https://github.com/tonsky/datascript/blob/master/src/datascript/db.cljc#L19-L22

pithyless19:11:12

As a rule of thumb, it's not recommended to expose the :db/id directly to an external API, but use a different stable unique identifier (or an UUID if nothing more relevant is available). This is a good idea even when working with Datomic directly (e.g. if you decide to re-transact your data into a new Datomic instance, you're not guaranteed to have the same eids).

lambdam19:11:44

Oh ok, I see. Very clear answer. Thanks a lot.