Schema API


The generic Schema interface provides attributes to build a Schema molecule that query the Schema structure of the current database. Datomic’s bootstrapped attributes are transparently filtered out so that only schema data of the current database is returned.

Generic Schema attributes

The following Schema attributes can be used to build Schema molecules:

Attribute    Description Example value
id    Attribute definition entity idLong
a    (Partition-)Namespace-prefixed attribute name     “:ind_Person/name” or “:Person/name” if no partitions
part    Partition name. “ind” or “” if no partitions
nsFull    Namespace name with partition prefix “ind_Person” or “Person” if no partitions
ns    Namespace name “Person”
attr    Attribute name “name”
tpe    Attribute Datomic type See types below
card    Attribute cardinality “one”/“many”
doc    Attribute documentation string String
index    Attribute index status true / not set
unique    Attribute uniqueness status true / not set
fulltext    Attribute fulltext search status true / not set
isComponent   Attribute isComponent status true / not set
noHistory    Attribute noHistory status true / not set
enum    Attribute enum values String
t    Attribute definition transaction point in time Long / Int
tx    Attribute definition transaction entity id Long
txInstant    Attribute definition transaction wall-clock time java.util.Date

Querying the Schema structure

// List of attribute entity ids
val attrIds: Seq[Long] =

Partition/Namespace/Attribute names

// Attribute name elements
Schema.a.part.ns.nsFull.attr.get === List (
  (":sales_Customer/name", "sales", "Customer", "sales_Customer", "name"),
  (":accounting_Invoice/invoiceLine", "accounting", "Invoice", "accounting_Invoice", "invoiceLine"),
  // etc..

Types and cardinality

// Datomic type and cardinality of attributes
Schema.a.tpe.card.get === List (
  (":sales_Customer/name", "string", "one"),
  (":accounting_Invoice/invoiceLine", "ref", "many")

Scala Int and Long are both represented as Datomic type long:

Datomic type     Scala type
string String
long Int
long Long
float Float
double Double
bigint BigInt
bigdec BigDecimal
boolean    Boolean
instant java.util.Date
uuid java.util.UUID
ref Long

Optional docs and attribute options

These can be retrieved as mandatory or optional attribute values

      .get === List(
    true,            // indexed
    "Customer name", // doc
    None,            // Uniqueness not set
    Some(true),      // Fulltext search set so that we can search for names
    None,            // Not a component
    None             // History is preserved (noHistory not set)
    true,                   // indexed
    "Ref to Invoice lines", // doc
    None,                   // Uniqueness not set
    None,                   // Fulltext search not set
    Some(true),             // Invoice is a component - owns invoice lines
    None                    // History is preserved (noHistory not set)

Enum values

Enumerated values can be defined in the schema and then retrieved generically with Schema.enum:

// Defined enum values
Schema.a.enum.get.groupBy(_._1).map(g => g._1 -> g._2) === Map(
  ":Person/gender" -> List("female", "male"),
  ":Interests/sports" -> List("golf", "basket", "badminton")

Schema transaction times

“In what transaction/when were the attributes created in the schema?”

Schema.t.tx.txInstant.get === List(
  (t1, tx1, <Date: 2018-11-07 09:28:10>), // Initial schema transaction
  (t2, tx2, <Date: 2019-01-12 12:43:27>), // Additional schema attribute definitions...