datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
lambdam 2020-11-30T18:56:26.061Z

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 "<mailto:foo@bar.com|foo@bar.com>"
 :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:
(-&gt;&gt; datomic-db
     (d/q '[:find ?user .
            :where [?user :user/email]])
     type)
;; =&gt; java.lang.Long

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

lambdam 2020-11-30T18:58:12.062500Z

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

pithyless 2020-11-30T19:39:28.065400Z

@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

pithyless 2020-11-30T19:43:12.068200Z

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

lambdam 2020-11-30T19:59:44.068700Z

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