Interface Database
-
public interface Database
An immutable, point-in-time database value.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Database.Predicate<T>
Boolean-valued function forfiltering
a database.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Object
AEVT
Names the AEVT index.static java.lang.Object
AVET
Names the AVET index.static java.lang.Object
EAVT
Names the EAVT index.static java.lang.Object
VAET
Names the VAET index.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Database
asOf(java.lang.Object t)
Returns the value of the database filtered to include data up tot
, inclusivejava.lang.Long
asOfT()
Attribute
attribute(java.lang.Object attrId)
Returns information about an attribute.long
basisT()
t value of the most recent transaction in this db.java.lang.Iterable<Datom>
datoms(java.lang.Object index, java.lang.Object... components)
Implements the Datoms API for raw access to matching index data.java.util.Map
dbStats()
Queries for database stats.java.lang.Object
entid(java.lang.Object entityId)
Returns the entity id associated with any kind of entity identifier.java.lang.Object
entidAt(java.lang.Object partition, java.lang.Object timePoint)
Returns a fabricated entity id in the supplied partition whose T component is at or after the supplied tEntity
entity(java.lang.Object entityId)
Returns an entity: a lazy, dynamic associative view of datoms sharing an entity id.Database
filter(Database.Predicate<Datom> pred)
Returns a value of the database containing only Datoms satisfying the predicate.Database
filter(java.lang.Object pred)
Database
history()
Returns a history database value containing all assertions and retractions across time.java.lang.String
id()
Opaque, globally unique database id.java.lang.Object
ident(java.lang.Object idOrKey)
Returns the symbolic keyword associated with an id, or the key itself if passed.java.util.stream.Stream<java.lang.Object>
indexPull(java.lang.Object options)
"Walks an index, pulling entities via :e if :avet or :v if :aevt, using the selector, returning a Stream of the results.java.lang.Iterable<Datom>
indexRange(java.lang.Object attrid, java.lang.Object start, java.lang.Object end)
Returns a range of AVET-indexed datoms.java.lang.Object
invoke(java.lang.Object entityId, java.lang.Object... args)
boolean
isFiltered()
Does database have a filter set with e.g.boolean
isHistory()
True for databases created withhistory()
long
nextT()
next t value that will be assigned by this database.java.util.Map
pull(java.lang.Object pattern, java.lang.Object entityId)
Returns a hierarchical selection of attributes for entityId.java.util.List<java.util.Map>
pullMany(java.lang.Object pattern, java.util.List entityIds)
Returns hierarchical selections of attributes for entityIds.java.lang.Iterable<Datom>
seekDatoms(java.lang.Object index, java.lang.Object... components)
Raw access to index data, starting at nearest match to inputDatabase
since(java.lang.Object t)
Returns the value of the database filtered to include only data sincet
, exclusivejava.lang.Long
sinceT()
java.util.Map
with(java.util.List txData)
Returns a database withtxData
applied locally in memory.
-
-
-
Field Detail
-
EAVT
static final java.lang.Object EAVT
Names the EAVT index.
Pass to APIs that take an index name such as
datoms(Object, Object...)
.
-
AEVT
static final java.lang.Object AEVT
Names the AEVT index.
Pass to APIs that take an index name such as
datoms(Object, Object...)
.
-
AVET
static final java.lang.Object AVET
Names the AVET index.
Pass to APIs that take an index name such as
datoms(Object, Object...)
.
-
VAET
static final java.lang.Object VAET
Names the VAET index.
Pass to APIs that take an index name such as
datoms(Object, Object...)
.
-
-
Method Detail
-
id
java.lang.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
java.lang.Long asOfT()
- Returns:
- a t value, or null
-
sinceT
java.lang.Long sinceT()
- Returns:
- a t value, or null
-
isHistory
boolean isHistory()
True for databases created withhistory()
- Returns:
- true for history databases
-
with
java.util.Map with(java.util.List txData)
Returns a database with
It is as if the data was applied in a transaction, but no actual transaction takes place.txData
applied locally in memory.- Parameters:
txData
- in the same format as expected bytransact
- Returns:
- a map as returned by transact
-
asOf
Database asOf(java.lang.Object t)
Returns the value of the database filtered to include data up tot
, inclusive- Parameters:
t
- a time-point- Returns:
- the value of the database as of some point t, inclusive
-
since
Database since(java.lang.Object t)
Returns the value of the database filtered to include only data sincet
, 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...)
andindexRange(Object, Object, Object)
, forqueries
, and forasOf(Object)
andsince(Object)
.A history database cannot be used with APIs that require a single point-in-time, i.e.
entity(Object)
orwith(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
Database filter(Database.Predicate<Datom> pred)
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 tofilter
compose predicates with logical 'and'.- Parameters:
pred
- aPredicate<Datom>
orclojure fn
- Returns:
- the value of the database satisfying the predicate
- Since:
- 0.8.3627
-
filter
Database filter(java.lang.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(java.lang.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(java.lang.Object attrId)
Returns information about an attribute.- Parameters:
attrId
- an entity identifier for an attribute- Returns:
- an Attribute}
- Since:
- 0.9.4470
-
ident
java.lang.Object ident(java.lang.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
java.lang.Object entid(java.lang.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
java.lang.Object entidAt(java.lang.Object partition, java.lang.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 partitiontimePoint
- a time-point- Returns:
- a fabricated entity id at or after some point t
-
invoke
java.lang.Object invoke(java.lang.Object entityId, java.lang.Object... args)
- Parameters:
entityId
- an entity identifierargs
- the arguments to the database function- Returns:
- the return value of the database function
-
datoms
java.lang.Iterable<Datom> datoms(java.lang.Object index, java.lang.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
-
seekDatoms
java.lang.Iterable<Datom> seekDatoms(java.lang.Object index, java.lang.Object... components)
Raw access to index data, starting at nearest match to input
. Arguments are the same as todatoms(java.lang.Object, java.lang.Object...)
, but their interpretation is different in two important ways:- The match need not be exact. Results will begin with the closest matching datom
- No termination. Results will continue all the way to the end of the index.
seekDatoms
is for more advanced applications, anddatoms(Object, Object...)
should be preferred wherever it is adequate.seekDatoms
is typically used in conjunction withentidAt(Object, Object)
to implement new entity scans.
-
indexRange
java.lang.Iterable<Datom> indexRange(java.lang.Object attrid, java.lang.Object start, java.lang.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 beginningend
- end value (non-inclusive), or null if through end- Returns:
- an
Iterable
overDatom
positioned between start (inclusive) and end (exclusive)
-
pull
java.util.Map pull(java.lang.Object pattern, java.lang.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
java.util.stream.Stream<java.lang.Object> indexPull(java.lang.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
: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 - a map that includes the
- Returns:
- an
Stream
of the indexPull results - Since:
- 0.9.6079
-
pullMany
java.util.List<java.util.Map> pullMany(java.lang.Object pattern, java.util.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
java.util.Map dbStats()
Queries for database stats.- Returns:
- a map with at least the following keys:
:datoms
total count of datoms in the (history) database
-
-