/translixir

Primary LanguageElixirGNU Lesser General Public License v3.0LGPL-3.0

Translixir

hex.pm hex.pm hex.pm hex.pm github.com

Elixir client for Crux DB, the general purpose database with bitemporal Datalog and SQL.

Bitemporal Crux

Crux is optimised for efficient and globally consistent point-in-time queries using a pair of transaction-time and valid-time timestamps.

Ad-hoc systems for bitemporal recordkeeping typically rely on explicitly tracking either valid-from and valid-to timestamps or range types directly within relations. The bitemporal document model that Crux provides is very simple to reason about and it is universal across the entire database, therefore it does not require you to consider which historical information is worth storing in special "bitemporal tables" upfront.

One or more documents may be inserted into Crux via a put transaction at a specific valid-time, defaulting to the transaction time (i.e. now), and each document remains valid until explicitly updated with a new version via put or deleted via delete.

Why?

Time Purpose
transaction-time Used for audit purposes, technical requirements such as event sourcing.
valid-time Used for querying data across time, historical analysis.

transaction-time represents the point at which data arrives into the database. This gives us an audit trail and we can see what the state of the database was at a particular point in time. You cannot write a new transaction with a transaction-time that is in the past.

valid-time is an arbitrary time that can originate from an upstream system, or by default is set to transaction-time. Valid time is what users will typically use for query purposes.

Reference crux bitemporality and value of bitemporality

Installation

The package can be installed by adding translixir to your list of dependencies in mix.exs:

def deps do
  [
    {:translixir, "~> 0.1.1"}
  ]
end

Creating a Crux Client

All operations with Translixir required a Translixir.Client. You can instantiate a new Agent containing the required information for a request with Translixir.Client.new(host, port) and set authorization header token with Translixir.Client.auth(<pid>, token).

  # Simple Client
    {:ok, client} = Client.new("localhost","3000")
    expected = %Client{host: "localhost", port: "3000"}
    assert Client.get(client) == expected


  # Client with Authorization
    {:ok, client} = Client.new("localhost","3000")
    Client.auth(client, "token")
    expected = %Client{host: "localhost", port: "3000", auth: "token"}
    assert Client.get(client) == expected

License

LGPL. Copyright (c) 2020 Julia Naomi.