Liking cljdoc? Tell your friends :D

Datahike babashka Pod

With the help of the Datahike cli we provide the possibility to run Datahike as a babashka pod.

Why Datahike as a babashka pod?

A babashka pod is a way to use Datahike in babashka without Datahike being built into the babashka binary. When you don't want to run a whole JVM for a little script you can use babashka and write your script in your preferred language. Babashka already has ways to persist data to other databases but Datahike adds the possibility to write to a durable datalog database.

babashka pod-registry

You can use the official babashka pod-registry to download the latest version of Datahike as a pod and run it with babashka.

Compilation

Please run bb ni-cli inside the datahike repository. You'll need GraalVM-JDK installed with native-compile on your path, babashka and Clojure.

Maturity

This feature is not used in production so far. Please try it and open issues on GitHub if you find a problem.

Supported functionality

  • as-of
  • connect
  • create-database
  • database-exists?
  • datoms (returns a seq of datoms as maps)
  • db
  • db-with
  • delete-database
  • entity (returns a simple map without further functionality)
  • history
  • metrics
  • pull
  • pull-many
  • q
  • release-db (release the DB-object to free memory)
  • since
  • schema
  • transact (returns the transaction-report as map)
  • with-db (a macro that avoids storing the DB-object)

Example usage

(ns pod
  (:require [babashka.pods :as pods]))

(pods/load-pod 'replikativ/datahike "0.7.1628") ;; Please check for the latest version

(require '[datahike.pod :as d])

(def config {:store  {:backend :file
                      :path "/tmp/bb-datahike-pod"}
             :keep-history? true
             :schema-flexibility :read})

(d/delete-database config)

(d/create-database config)

(def conn (d/connect config))

(d/transact conn [{:name  "Alice", :age   20}
                  {:name  "Bob", :age   30}
                  {:name  "Charlie", :age   40}
                  {:age 15}])

(def db (d/db conn))

(d/q '[:find ?e ?n ?a
       :where
       [?e :name ?n]
       [?e :age ?a]]
     db)

(release-db db)

(d/pull (d/db conn) '[*] 3)

(with-db [db (db conn)]
  (q {:query '{:find [?e ?a ?v]
      :where
      [[?e ?a ?v]]}}
     db))

Can you improve this documentation? These fine people already did:
Christian Weilbach, Coby Tamayo & Timo Kramer
Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close