Querying for historical values, and creation and modification timestamps as dateTime

I read that dgraph is configuring badger to keep all value mutations in the log permanently:

options.NumVersionsToKeep . We set this by default to 1 in Badger, but in Dgraph, we set this to infinity

So… My question is, can we access that “infinite history” via dgraph queries?

I am experimenting with adding explicit created and modified dateTime predicates, but it feels like this could/should be provided via an implicit function of some sort.
Intuitively i would like this kind of query:

{
  everyone(func: eq(dgraph.type, "Person")) {
    uid
    created as @created(uid)
    modified as @modified(uid)
    seconds_since_created: math(since(created))
    name@* @facets @history
  }
}

to return this kind of result:

{
  "data": {
    "everyone": [
      {
        "uid": "0x2737",
        "created": "2020-07-29T12:50:41.849Z",
        "modified": "2020-07-29T14:10:05.56Z",
        "seconds_since_created": 4799.593736,
        "name@en": "Hyong Sin",
        "name@en|isChanged" : true,
        "name@en|history": {
               "2020-07-29T14:10:05.56Z":"Hyung Sin"
        },
        "name@ko": "형신"
      },

Is there any undocumented magic (or magic that i didn’t manage to find in the docs) to do such things?

If not, could this be a feature request? Would it be reasonably easy to implement because of the way badger ~is_working with dgraph ?

1 Like