Open Time Store™
Copyright © JUXT LTD 2018-2019

Introduction

This guide contains simple steps showing how to transact data and run a simple query. However, there are a few topics you might benefit from learning about before you get too far with attempting to use Crux:

  • EDN – the extensible data notation format used throughout the Crux APIs, see Essential EDN for Crux.

  • The Datalog query language – Crux supports an EDN-flavoured version of Datalog. The Queries section within this documentation provides a good overview. You can also find an interactive tutorial for EDN-flavoured Datalog here.

  • Clojure – whilst a complete Java API is provided, a basic understanding of Clojure is recommended – Clojure is a succinct and pragmatic data-oriented language with strong support for immutability and parallelism. See Clojure.org.

Setting Up

Follow the below steps to quickly set yourself up a Crux playground:

Project Dependency

First add Crux as a project dependency:

  juxt/crux-core {:mvn/version "19.09-1.4.0-alpha"}

Start a Crux node

(require '[crux.api :as crux])
(import (crux.api ICruxAPI))

(def ^crux.api.ICruxAPI node
  (crux/start-standalone-node {:kv-backend "crux.kv.memdb.MemKv"
                               :db-dir "data/db-dir-1"
                               :event-log-dir "data/eventlog-1"}))

For the purposes of this Hello World, we are using the simplest configuration of Crux, where all of the pluggable components are in-memory. There is no Kafka or RocksDB to worry about.

Transacting

(crux/submit-tx
 node
 [[:crux.tx/put
   {:crux.db/id :dbpedia.resource/Pablo-Picasso ; id
    :name "Pablo"
    :last-name "Picasso"}
   #inst "2018-05-18T09:20:27.966-00:00"]]) ; valid time

Querying

(crux/q (crux/db node)
       '{:find [e]
         :where [[e :name "Pablo"]]})

You should get:

  #{[:dbpedia.resource/Pablo-Picasso]}

An entity query would be:

(crux/entity (crux/db node) :dbpedia.resource/Pablo-Picasso)

You should get:

  {:crux.db/id :dbpedia.resource/Pablo-Picasso
   :name "Pablo"
   :last-name "Picasso"}

Next Steps

Now you know the basics of how to interact with Crux you may want to dive into our tutorials. Otherwise, let’s take a look at the kinds of things you are able to do with Queries.