Datomic time queries

Hi guys,

Imagine having the following Datomic schema:

    [{:db/ident       :group/name
      :db/valueType   :db.type/string
      :db/cardinality :db.cardinality/one
      :db/unique      :db.unique/value
      :db/doc         "group name"}
     {:db/ident       :group/items
      :db/valueType   :db.type/ref
      :db/cardinality :db.cardinality/many
      :db/isComponent true
      :db/doc         "group items"}
     {:db/ident       :item/t
      :db/valueType   :db.type/instant
      :db/cardinality :db.cardinality/one
      :db/doc         "item t"}
     {:db/ident       :item/content
      :db/valueType   :db.type/bytes
      :db/cardinality :db.cardinality/one
      :db/doc         "item content"}]

And also imagine that a certain group has millions of items.

Is there any efficient way to make queries such as:

  • last item before or at ‘some-t’
  • next item after ‘some-t’

Datomic has worked out so incredibly well for everything, I would hate this one small bit to make me move to another database.

Many thanks in advance for any suggestions!

Regards,
Mykola

If time is your most selective attribute, you should use the Log API.

There are some minor differences in the API between Datomic Cloud and Datomic On-Prem:

Datomic Cloud: https://docs.datomic.com/cloud/time/log.html
https://github.com/cognitect-labs/day-of-datomic-cloud/blob/master/tutorial/log.clj

Datomic On-Prem: https://docs.datomic.com/on-prem/log.html
https://github.com/Datomic/day-of-datomic/blob/master/tutorial/log.clj and https://github.com/Datomic/day-of-datomic/blob/master/tutorial/time-rules.clj

thank you marshall,

I have played with the APIs, and a few different indexing options, it looks like handling millions of records in the same series isn’t something Datomic is optimised for. I might need some TSDB for this.
Anyway, Datomic is fantastic for pretty much everything else in the world :slight_smile:

Cheers,
Mykola