At database creation datahike supports features that can be
configured based on the application's requirements. As of version 0.2.0
configuration for the storage backend, the schema
flexibility, and the
time variance is supported.
Be aware: all these features can be set at database creation
but can not be changed afterwards.
The backend configuration can be encoded within a base uri we can connect to. It has the following scheme:
datahike:<backend>://(<username>:<password>@)<host>:<port><path>
Each backend needs a different set of provided parameters. See definition below for further information. For simple and fast creation you can simple type:
(:require '[datahike.api :as d])
(def uri "datahike:mem://example")
(d/create-database uri)
If you prefer data structures for configuration you may use a hash map. The example above looks like:
(:require '[datahike.api :as d])
(def config {:backend :mem :host "example"})
(d/create-database config)
At the moment we support four different backends: in-memory ,file-based, LevelDB, and PostgreSQL.
<backend>
: mem
host
: name of the databasedatahike:mem://mem-example
{:backend :mem :host "mem-example"}
<backend>
: file
path
: absolute path to the storage folderdatahike:file:///tmp/file-example
{:backend :file :path "/tmp/file-example"}
<backend>
: level
path
: absolute path to the LevelDB instancedatahike:level:///tmp/level-example
{:backend :level :path "/tmp/level-example"}
<backend>
: pg
username
: PostgreSQL instance usernamepassword
: PostgreSQL instance passwordhost
: PostgreSQL instance hostport
: PostgreSQL instance portpath
: name of the PostgreSQL database, must be present in the instancedatahike:pg://alice:foobar@localhost:5432/pg_example
{:backend :pg :host "localhost" :port 5432 :username "alice" :password "foobar" :path "/pg_example"}
By default the datahike api uses a schema-on-write
approach with strict value
types that need to be defined in advance. If you are not sure how your data
model looks like and you want to transact any kind of data into the database you
can set schema-on-read
to true
by adding it as optional parameter at
database creation. You may add basic schema definitions like :db/unique
,
:db/cardinality
or db.type/ref
where these kind of structure is needed.
(:require '[datahike.api :as d])
(d/create-database "datahike:mem://example" :schema-on-read true)
Have a look at the schema documentation for more information.
Datahike has the capability to inspect and query historical data within temporal
indices. If your application does not require any temporal data, you may
set :temporal-index
to false
.
(:require '[datahike.api :as d])
(d/create-database "datahike:mem://example" :temporal-index false)
Be aware: when deactivating the temporal index you may not use any temporal databases like history
, as-of
, or
since
.
Refer to the time variance documentation for more information.
Can you improve this documentation? These fine people already did:
Konrad Kühne & Christian WeilbachEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close