Skip to content

Instantly share code, notes, and snippets.

@arohner
Created May 25, 2015 16:00
Show Gist options
  • Select an option

  • Save arohner/d7a6bb057824c224b5b3 to your computer and use it in GitHub Desktop.

Select an option

Save arohner/d7a6bb057824c224b5b3 to your computer and use it in GitHub Desktop.

Revisions

  1. arohner created this gist May 25, 2015.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    ;;; Extremely incomplete type annotations for Datomic.

    (ns foo.util.type.datomic
    (:require [clojure.core.typed :as t]
    [datomic.api :as d])
    (:import (datomic Connection
    Database)
    (datomic.db DbId)
    (java.util Date UUID)))

    (t/ann ^:no-check datomic.api/tempid [t/Keyword -> datomic.db.DbId])

    (t/defalias TxVal (t/U DbId t/AnyInteger String Boolean BigInteger Double BigDecimal Date UUID (Array byte)))
    (t/defalias TxAttr t/Keyword)
    (t/defalias TxVec (t/HVec [t/Keyword TxAttr TxVal])) ;; [:db/add e a v]
    (t/defalias TxMap (t/Map TxAttr TxVal))
    (t/defalias TxDatom (t/U TxVec TxMap))
    (t/defalias TxData (t/Vec TxDatom))

    (t/ann ^:no-check datomic.api/db [Connection -> Database])

    (t/defalias TxResult (t/HMap :mandatory {}))
    (t/ann ^:no-check datomic.api/transact [Connection TxData -> (t/Future TxResult)])

    (t/defalias PullPattern (t/Vec t/Any))
    (t/ann ^:no-check datomic.api/pull [Database PullPattern Long -> (t/Map TxAttr TxVal)])

    (t/defalias Query (t/Vec t/Any))
    (t/ann ^:no-check datomic.api/q [Query Database TxVal * -> t/Any])