Package datomic

Interface Database


public interface Database
An immutable, point-in-time database value.
  • Field Details

  • Method Details

    • id

      String id()
      Opaque, globally unique database id.
      Returns:
      the database id
    • basisT

      long basisT()
      t value of the most recent transaction in this db.
      Returns:
      a t value
    • nextT

      long nextT()
      next t value that will be assigned by this database.
      Returns:
      a t value
    • asOfT

      Long asOfT()
      Returns:
      a t value, or null
    • sinceT

      Long sinceT()
      Returns:
      a t value, or null
    • isHistory

      boolean isHistory()
      True for databases created with history()
      Returns:
      true for history databases
    • with

      Map with(List txData)

      Returns a database with txData applied locally in memory.

      It is as if the data was applied in a transaction, but no actual transaction takes place.
      Parameters:
      txData - in the same format as expected by transact
      Returns:
      a map as returned by transact
    • asOf

      Database asOf(Object t)
      Returns the value of the database filtered to include data up to t, inclusive
      Parameters:
      t - a time-point
      Returns:
      the value of the database as of some point t, inclusive
    • since

      Database since(Object t)
      Returns the value of the database filtered to include only data since t, exclusive
      Parameters:
      t - a time-point
      Returns:
      the value of the database since some point t, exclusive
    • history

      Database history()

      Returns a history database value containing all assertions and retractions across time.

      A history database can be used for datoms(Object, Object...) and indexRange(Object, Object, Object), for queries, and for asOf(Object) and since(Object).

      A history database cannot be used with APIs that require a single point-in-time, i.e. entity(Object) or with(java.util.List).

      Note that queries will return all of the additions and retractions, which can be distinguished by Datom.added()

      Returns:
      a history Database
    • filter

      Returns a value of the database containing only Datoms satisfying the predicate.

      The predicate will be passed the unfiltered db and a Datom Chained calls to filter compose predicates with logical 'and'.
      Parameters:
      pred - a Predicate<Datom> or clojure fn
      Returns:
      the value of the database satisfying the predicate
      Since:
      0.8.3627
    • filter

      Database filter(Object pred)
    • isFiltered

      boolean isFiltered()
      Does database have a filter set with e.g. filter(datomic.Database.Predicate)?
      Returns:
      true if db has a filter
      Since:
      0.8.3627
    • entity

      Entity entity(Object entityId)
      Returns an entity: a lazy, dynamic associative view of datoms sharing an entity id.
      Parameters:
      entityId - an entity identifier
      Returns:
      an Entity
    • attribute

      Attribute attribute(Object attrId)
      Returns information about an attribute.
      Parameters:
      attrId - an entity identifier for an attribute
      Returns:
      an Attribute}
      Since:
      0.9.4470
    • ident

      Object ident(Object idOrKey)
      Returns the symbolic keyword associated with an id, or the key itself if passed.
      Parameters:
      idOrKey - an id or keyword
      Returns:
      a keyword, or nil if not found
    • entid

      Object entid(Object entityId)
      Returns the entity id associated with any kind of entity identifier.
      Parameters:
      entityId - an entity identifier
      Returns:
      an id, or nil if not found
    • entidAt

      Object entidAt(Object partition, Object timePoint)

      Returns a fabricated entity id in the supplied partition whose T component is at or after the supplied t

      . Entity ids sort by partition, then T component, such T components interleaving with transaction numbers. Thus this method can be used to fabricate a time-based entity id component for use in #seekDatoms.
      Parameters:
      partition - an entity identifier for a partition
      timePoint - a time-point
      Returns:
      a fabricated entity id at or after some point t
    • invoke

      Object invoke(Object entityId, Object... args)
      Look up the database function of the entity at entityId, and invoke the function with args.
      Parameters:
      entityId - an entity identifier
      args - the arguments to the database function
      Returns:
      the return value of the database function
    • datoms

      Iterable<Datom> datoms(Object index, Object... components)

      Implements the Datoms API for raw access to matching index data.

      The index must be supplied, and, optionally, one or more leading components of the index can be supplied to narrow the result. EAVT and AEVT indexes will contain all datoms AVET will contain datoms for attributes where either :db/index or :db/unique are true. VAET will contain datoms for attributes of :db.type/ref - it is the reverse index
      Parameters:
      index - one of EAVT, AEVT, AVET, or VAET
      components - supply any datom components to match, in order corresponding to the index
      Returns:
      the datoms in the specified index matching the specified components
    • seekDatoms

      Iterable<Datom> seekDatoms(Object index, Object... components)

      Raw access to index data, starting at nearest match to input

      . Arguments are the same as to datoms(java.lang.Object, java.lang.Object...), but their interpretation is different in two important ways:
      1. The match need not be exact. Results will begin with the closest matching datom
      2. No termination. Results will continue all the way to the end of the index.
      seekDatoms is for more advanced applications, and datoms(Object, Object...) should be preferred wherever it is adequate. seekDatoms is typically used in conjunction with entidAt(Object, Object) to implement new entity scans.
      Parameters:
      index - one of EAVT, AEVT, AVET, or VAET
      components - supply any datom components to search for, in order corresponding to the index
      Returns:
      all of the datoms in the specified index at or after the specified components
    • indexRange

      Iterable<Datom> indexRange(Object attrid, Object start, Object end)

      Returns a range of AVET-indexed datoms.

      Parameters:
      attrid - an entity identifier naming an indexed attribute.
      start - start value or null if from beginning
      end - end value (non-inclusive), or null if through end
      Returns:
      an Iterable over Datom positioned between start (inclusive) and end (exclusive)
    • pull

      Map pull(Object pattern, Object entityId)
      Returns a hierarchical selection of attributes for entityId.
      Parameters:
      pattern - A pattern, or a String containing a pattern serialized into edn.
      entityId - An entity identifier
      Returns:
      A map containing a selection for the entityId passed in.
      Since:
      0.9.5040
    • indexPull

      Stream<Object> indexPull(Object options)
      "Walks an index, pulling entities via :e if :avet or :v if :aevt, using the selector, returning a Stream of the results.
      Parameters:
      options - a data structure describing the indexPull serialized into edn
      • a map that includes the :index, :selector, :start, and :reverse keys
      indexPull map keys
      :index  :avet or :aevt
      :selector  a pull selector (see 'pull')
      :start  A vector in the same order as the index indicating the initial position. At least :a must be specified. Iteration is limited to datoms matching :a.
      :reverse  optional, when true iterate the index in reverse order
      Returns:
      an Stream of the indexPull results
      Since:
      0.9.6079
    • pullMany

      List<Map> pullMany(Object pattern, List entityIds)
      Returns hierarchical selections of attributes for entityIds.
      Parameters:
      pattern - A pattern, or a String containing a pattern serialized into edn.
      entityIds - A list of entity identifiers
      Returns:
      A list of maps containing a selection for each entityId passed in.
      Since:
      0.9.5040
    • dbStats

      Map dbStats()
      Queries for database stats.
      Returns:
      a map with at least the following keys:
      dbStats return keys
      :datoms  total count of datoms in the (history) database