aarondb/fact

Types

pub type Attribute =
  String
pub type AttributeConfig {
  AttributeConfig(
    unique: Bool,
    component: Bool,
    retention: Retention,
    cardinality: Cardinality,
    check: option.Option(String),
    composite_group: option.Option(String),
    layout: StorageLayout,
    tier: StorageTier,
    eviction: EvictionPolicy,
  )
}

Constructors

pub type Cardinality {
  One
  Many
}

Constructors

  • One
  • Many
pub type Datom {
  Datom(
    entity: EntityId,
    attribute: String,
    value: Value,
    tx: Int,
    tx_index: Int,
    valid_time: Int,
    operation: Operation,
  )
}

Constructors

  • Datom(
      entity: EntityId,
      attribute: String,
      value: Value,
      tx: Int,
      tx_index: Int,
      valid_time: Int,
      operation: Operation,
    )
pub type DbFunction(state) =
  fn(state, Int, Int, List(Value)) -> List(#(Eid, String, Value))
pub type Eid {
  Lookup(#(String, Value))
  Uid(EntityId)
}

Constructors

pub type Entity =
  EntityId
pub type EntityId {
  EntityId(Int)
}

Constructors

  • EntityId(Int)
pub type EvictionPolicy {
  AlwaysInMemory
  LRU(Int)
  LruToDisk
}

Constructors

  • AlwaysInMemory
  • LRU(Int)
  • LruToDisk

A Fact is #(Eid, Attribute, Value) for assertion, or a more explicit Tuple for retractions.

pub type Fact =
  #(Eid, String, Value)
pub type LookupRef =
  #(String, Value)
pub type Operation {
  Assert
  Retract
}

Constructors

  • Assert
  • Retract
pub type Retention {
  All
  LatestOnly
  Last(Int)
}

Constructors

  • All
  • LatestOnly
  • Last(Int)
pub type StorageLayout {
  Row
  Columnar
}

Constructors

  • Row
  • Columnar
pub type StorageTier {
  Memory
  Disk
}

Constructors

  • Memory
  • Disk
pub type Transaction =
  Int
pub type Value {
  Str(String)
  Int(Int)
  Float(Float)
  Bool(Bool)
  List(List(Value))
  Vec(List(Float))
  Ref(EntityId)
  Map(dict.Dict(String, Value))
  Blob(BitArray)
}

Constructors

  • Str(String)
  • Int(Int)
  • Float(Float)
  • Bool(Bool)
  • List(List(Value))
  • Vec(List(Float))
  • Ref(EntityId)
  • Map(dict.Dict(String, Value))
  • Blob(BitArray)

Values

pub fn compare(v1: Value, v2: Value) -> order.Order
pub fn decode_compact(
  bits: BitArray,
) -> Result(#(Value, BitArray), Nil)
pub fn decode_datom(
  bits: BitArray,
) -> Result(#(Datom, BitArray), Nil)
pub fn deterministic_uid(data: a) -> Eid

Create a deterministic Entity ID based on a hash of the data. This enables idempotent transaction semantics.

pub fn eid_to_integer(eid: EntityId) -> Int
pub fn encode_compact(v: Value) -> BitArray
pub fn encode_datom(d: Datom) -> BitArray
pub fn event_uid(event_type: String, timestamp: Int) -> Eid

Create a unique, deterministic Entity ID for an event based on its type and timestamp. This ensures that the same event instance (e.g. from retries) always gets the same ID.

pub fn integer_to_eid(i: Int) -> EntityId
pub fn new_datom(
  entity entity: EntityId,
  attribute attribute: String,
  value value: Value,
  tx tx: Int,
  tx_index tx_index: Int,
  operation operation: Operation,
) -> Datom

Create a new Datom with default valid_time = 0.

pub fn phash2(data: a) -> Int
pub fn ref(id: Int) -> EntityId
pub fn to_string(v: Value) -> String
pub fn to_uid(id: EntityId) -> Eid
pub fn uid(id: Int) -> Eid
Search Document