{"id":16115041,"url":"https://github.com/naomijub/translixir","last_synced_at":"2025-03-18T10:30:28.796Z","repository":{"id":54866607,"uuid":"303896773","full_name":"naomijub/translixir","owner":"naomijub","description":"Crux Database Client","archived":false,"fork":false,"pushed_at":"2021-01-24T03:59:53.000Z","size":81,"stargazers_count":18,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-28T08:46:00.317Z","etag":null,"topics":["client","crux","database"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/translixir/readme.html","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/naomijub.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-14T03:53:19.000Z","updated_at":"2024-06-06T00:40:05.000Z","dependencies_parsed_at":"2022-08-14T05:10:30.317Z","dependency_job_id":null,"html_url":"https://github.com/naomijub/translixir","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naomijub%2Ftranslixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naomijub%2Ftranslixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naomijub%2Ftranslixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naomijub%2Ftranslixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naomijub","download_url":"https://codeload.github.com/naomijub/translixir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243918620,"owners_count":20368745,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","crux","database"],"created_at":"2024-10-09T20:17:05.467Z","updated_at":"2025-03-18T10:30:28.349Z","avatar_url":"https://github.com/naomijub.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Translixir\n\n[![hex.pm](https://img.shields.io/hexpm/v/translixir.svg)](https://hex.pm/packages/translixir)\n[![hex.pm](https://img.shields.io/badge/docs-hexpm-blue.svg)](https://hexdocs.pm/translixir)\n[![hex.pm](https://img.shields.io/hexpm/dt/translixir.svg)](https://hex.pm/packages/translixir)\n[![hex.pm](https://img.shields.io/hexpm/l/translixir.svg)](https://hex.pm/packages/translixir)\n[![github.com](https://img.shields.io/github/last-commit/naomijub/translixir.svg)](https://github.com/naomijub/translixir/commits/master)\n\nElixir client for [Crux DB](https://www.opencrux.com), the general purpose\ndatabase with bitemporal Datalog and SQL.\n- [x] Via `Docker` with a [`crux-standalone`](https://opencrux.com/reference/building.html#_docker) version [docker-hub](https://hub.docker.com/r/juxt/crux-standalone). Current Docker image `juxt/crux-standalone:20.09-1.11.0`. **Via github dependency**\n- [x] Via [`HTTP`](https://opencrux.com/reference/http.html#start-http-server) using the [`HTTP API`](https://opencrux.com/reference/http.html#http-api). **Via github dependency**\n- [ ] Missing entity_history with time-stamps\n\n* [**Crux Getting Started**](https://opencrux.com/reference/get-started.html)\n* [**Crux FAQs**](https://opencrux.com/about/faq.html)\n* [**Rust Client** as inspiration](https://github.com/naomijub/transistor)\n\n## Bitemporal Crux\n\nCrux is optimised for efficient and globally consistent point-in-time queries using a pair of transaction-time and valid-time timestamps.\n\nAd-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.\n\nOne 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.\n\n### Why?\n\n| Time \t| Purpose \t|\n|-\t|-\t|\n| transaction-time \t| Used for audit purposes, technical requirements such as event sourcing. \t|\n| valid-time \t| Used for querying data across time, historical analysis. \t|\n\n`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.\n\n`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.\n\nReference [crux bitemporality](https://opencrux.com/about/bitemporality.html) and [value of bitemporality](https://juxt.pro/blog/posts/value-of-bitemporality.html)\n\n\n## Installation\n\nThe package can be installed by adding `translixir` to your list of\ndependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:translixir, \"~\u003e 0.4\"}\n  ]\nend\n```\n\n## Creating a Crux Client\n\nAll 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(\u003cpid\u003e, token)`.\n\n```elixir\n# Simple Client\n  {:ok, client} = Client.new(\"localhost\",\"3000\")\n  expected = %Client{host: \"localhost\", port: \"3000\"}\n  assert Client.get(client) == expected\n\n\n# Client with Authorization\n  {:ok, client} = Client.new(\"localhost\",\"3000\")\n  Client.auth(client, \"token\")\n  expected = %Client{host: \"localhost\", port: \"3000\", auth: \"token\"}\n  assert Client.get(client) == expected\n```\n\n## Building a `tx_log::Action` to Insert in database\n* use module `Translixir.Model.Action`\n\n```elixir\nalias Translixir.Model.Action\n\nactions =\n  Action.new()\n  |\u003e Action.add_action(Action.evict(:hello))\n  |\u003e Action.add_action(\n    Action.delete(:my_id, DateTime.from_naive!(~N[2020-10-10 13:26:08.003], \"Etc/UTC\"))\n  )\n  |\u003e Action.actions()\n\nassert actions ==\n          \"[[:crux.tx/evict :hello] [:crux.tx/delete :my_id #inst \\\"2020-10-10T13:26:08.003%2B00:00\\\"]]\"\n```\n\nPossible Actions:\n```elixir\nalias Translixir.Model.Action\n\nactual = Action.put(:my_id, %{first_name: \"test\", last_name: \"wow\"})\nexpected = \"[:crux.tx/put {:crux.db/id :my_id, :first_name \\\"test\\\", :last_name \\\"wow\\\"}]\"\nassert actual == expected\n\nactual =\n  Action.put(\n    :my_id,\n    %{first_name: \"test\", last_name: \"wow\"},\n    DateTime.from_naive!(~N[2020-10-10 13:26:08.003], \"Etc/UTC\")\n  )\nexpected =\n  \"[:crux.tx/put {:crux.db/id :my_id, :first_name \\\"test\\\", :last_name \\\"wow\\\"} #inst \\\"2020-10-10T13:26:08.003%2B00:00\\\"]\"\nassert actual == expected\n\nactual = Action.delete(:my_id)\nexpected = \"[:crux.tx/delete :my_id]\"\nassert actual == expected\n\nactual = Action.delete(:my_id, DateTime.from_naive!(~N[2020-10-10 13:26:08.003], \"Etc/UTC\"))\nexpected = \"[:crux.tx/delete :my_id #inst \\\"2020-10-10T13:26:08.003%2B00:00\\\"]\"\nassert actual == expected\n\nassert Action.evict(3) == \"[:crux.tx/evict 3]\"\nassert Action.evict(:my_id) == \"[:crux.tx/evict :my_id]\"\n```\n\n## Building a Query\n* Use module `Translixir.Model.Query`\n\n```elixir\nalias Translixir.Model.Query\n\nactual =\n  Query.find(%{}, [\"?h\", \"?q\"])\n  |\u003e Query.where([\"?p1 :name ?n\", \"?p1 :is-sql true\"])\n  |\u003e Query.build()\nexpected = \"{:query {:find [?h ?q], :where [[?p1 :name ?n] [?p1 :is-sql true]]}}\"\nassert actual == expected\n\nassert catch_error(Query.find(%{}, [\":hello\", \":world\"])) ==\n          %RuntimeError{message: \"All keys should be atoms or strings starting with `?`\"}\n\nactual =\n  Query.find(%{}, [\"?h\", \"?q\"])\n  |\u003e Query.where([\"?p1 :name ?n\", \"?p1 :is-sql ?s\"])\n  |\u003e Query.args([\"?s true\"])\n  |\u003e Query.build()\nexpected =\n  \"{:query {:args [{?s true}], :find [?h ?q], :where [[?p1 :name ?n] [?p1 :is-sql ?s]]}}\"\nassert actual == expected\n\nactual =\n  Query.find(%{}, [\"?h\", \"?q\"])\n  |\u003e Query.where([\"?p1 :name ?n\", \"?p1 :is-sql ?s\"])\n  |\u003e Query.limit(5)\n  |\u003e Query.offset(20)\n  |\u003e Query.build()\nexpected =\n  \"{:query {:find [?h ?q], :limit 5, :offset 20, :where [[?p1 :name ?n] [?p1 :is-sql ?s]]}}\"\nassert actual == expected\n\nactual =\n  Query.find(%{}, [:h, :q])\n  |\u003e Query.where([\"?p1 :name ?n\", \"?p1 :is-sql ?s\"])\n  |\u003e Query.order_by([\"?s true\"])\n  |\u003e Query.with_full_results()\n  |\u003e Query.build()\nexpected =\n  \"{:query {:find [?h ?q], :full-results? true, :order-by [[?s true]], :where [[?p1 :name ?n] [?p1 :is-sql ?s]]}}\"\nassert actual == expected\n```\n\n## Functions examples\n\n```elixir\nalias Translixir.Http.Client\nalias Translixir.Model.Action\n\nclient = Client.new(\"localhost\", \"3000\")\nput = Action.new()\n  |\u003e Action.add_action(Action.put(:hello, %{first_name: \"Hello\", last_name: \"World\"}))\n  |\u003e Action.add_action(Action.delete(:delete_id))\n  |\u003e Action.actions()\n\nclient |\u003e Translixir.tx_log(put)\n# {:ok, %{\"crux.tx/tx-id\": 7, \"crux.tx/tx-time\": ~U[2020-10-25 04:33:41.102Z]}}\n\nclient |\u003e Translixir.entity(:hello) |\u003e IO.inspect()\n# {:ok, %{\"crux.db/id\": :hello, first_name: \"Hello\", last_name: \"World\"}}\n\n```\n\n## License\n\n[LGPL](LICENSE). Copyright (c) 2020 Julia Naomi.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaomijub%2Ftranslixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaomijub%2Ftranslixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaomijub%2Ftranslixir/lists"}