├── java
├── .mvn
│ └── jvm.config
├── src
│ └── main
│ │ ├── resources
│ │ └── logback.xml
│ │ └── java
│ │ └── xtdbinabox
│ │ └── Box.java
├── config.json
├── Makefile
└── pom.xml
├── .gitignore
├── README.md
├── clj
├── resources
│ └── logback.xml
├── src
│ └── xtdb_in_a_box
│ │ └── db.clj
└── project.clj
└── LICENSE
/java/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | -Dclojure.tools.logging.factory=clojure.tools.logging.impl/slf4j-factory
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | clj/**/pom.xml
2 | clj/**/pom.xml.asc
3 | *.jar
4 | *.class
5 | /lib/
6 | /classes/
7 | /target/
8 | /checkouts/
9 | .lein-deps-sum
10 | .lein-repl-history
11 | .lein-plugins/
12 | .lein-failures
13 | .nrepl-port
14 | .cpcache/
15 | .lsp/
16 | clj/data/
17 | clj/target/
18 | java/data/
19 | java/target/
20 | java/.classpath
21 | java/.project
22 | .settings/
23 | .vscode/
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # xtdb-in-a-box
2 |
3 | The simplest production-ready Xtdb setup.
4 |
5 | Please read the [XTDB Quickstart](https://docs.xtdb.com/guides/quickstart/).
6 |
7 | ## Clojure
8 |
9 | The `/clj` directory contains a minimal Clojure project. Run it from a REPL.
10 |
11 | ## Java
12 |
13 | The `/java` directory contains a minimal Java project. Run it with:
14 |
15 | ```shell
16 | make && make run
17 | ```
18 |
19 | ## License
20 |
21 | Copyright © 2021 JUXT Ltd.
22 |
23 | Distributed under the MIT License.
24 |
--------------------------------------------------------------------------------
/clj/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %-5level %logger{36} - %msg%n
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/java/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %-5level %logger{36} - %msg%n
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/java/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "xtdb/index-store": {
3 | "kv-store": {
4 | "xtdb/module": "xtdb.rocksdb/->kv-store",
5 | "db-dir": "data/index-store"
6 | }
7 | },
8 | "xtdb/document-store": {
9 | "kv-store": {
10 | "xtdb/module": "xtdb.rocksdb/->kv-store",
11 | "db-dir": "data/doc-store"
12 | }
13 | },
14 | "xtdb/tx-log": {
15 | "kv-store": {
16 | "xtdb/module": "xtdb.rocksdb/->kv-store",
17 | "db-dir": "data/tx-log"
18 | }
19 | },
20 | "xtdb.lucene/lucene-store": {
21 | "db-dir": "data/dev/lucene-dir"
22 | },
23 | "xtdb.http-server/server": {
24 | "port": 9999
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/java/Makefile:
--------------------------------------------------------------------------------
1 |
2 | build:
3 | mvn dependency:copy-dependencies
4 | mvn package # alternatively: `mvn clean compile assembly:single`
5 |
6 | # MacOS + JDK16/17 workarounds:
7 | # (1) `XTDB_ENABLE_BYTEUTILS_SHA1` is required to change the SHA1 algorithm used.
8 | # (2) `--add-opens java.base/java.util.concurrent=ALL-UNNAMED` is required to avoid
9 | # https://github.com/xtdb/xtdb/issues/1462
10 | run:
11 | XTDB_ENABLE_BYTEUTILS_SHA1=true \
12 | java -cp target/xtdbinabox-0.0.2-jar-with-dependencies.jar \
13 | -Dclojure.tools.logging.factory=clojure.tools.logging.impl/slf4j-factory \
14 | --add-opens java.base/java.util.concurrent=ALL-UNNAMED \
15 | xtdbinabox.Box
16 |
17 | sanity:
18 | java --version
19 | mvn --version
20 |
--------------------------------------------------------------------------------
/clj/src/xtdb_in_a_box/db.clj:
--------------------------------------------------------------------------------
1 | (ns xtdb-in-a-box.db
2 | (:require [clojure.java.io :as io]
3 | [xtdb.api :as xt]))
4 |
5 | (println (System/getenv "XTDB_ENABLE_BYTEUTILS_SHA1"))
6 |
7 | (defn start-xtdb! []
8 | (letfn [(kv-store [dir]
9 | {:kv-store {:xtdb/module 'xtdb.rocksdb/->kv-store
10 | :db-dir (io/file dir)
11 | :sync? true}})]
12 | (xt/start-node
13 | {:xtdb/tx-log (kv-store "data/dev/tx-log")
14 | :xtdb/document-store (kv-store "data/dev/doc-store")
15 | :xtdb/index-store (kv-store "data/dev/index-store")
16 | ;; optional:
17 | :xtdb.lucene/lucene-store {:db-dir "data/dev/lucene-dir"}
18 | :xtdb.http-server/server {:port 9999}})))
19 |
20 | (def xtdb-node (start-xtdb!))
21 |
22 | (defn stop-xtdb! []
23 | (.close xtdb-node))
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Steven Deobald
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/clj/project.clj:
--------------------------------------------------------------------------------
1 | (defproject xtdb-in-a-box "0.0.2"
2 | :description "XTDB in a Box"
3 |
4 | :dependencies [[org.clojure/clojure "1.10.1"]
5 |
6 | ;; required:
7 | [com.xtdb/xtdb-core "1.23.2"]
8 | [com.xtdb/xtdb-rocksdb "1.23.2"]
9 |
10 | ;; logging:
11 | [org.clojure/tools.logging "1.1.0"]
12 | [ch.qos.logback/logback-classic "1.2.3"]
13 | [ch.qos.logback/logback-core "1.2.3"]
14 | [org.slf4j/slf4j-api "1.7.30"]
15 |
16 | ;; optional:
17 | [com.xtdb/xtdb-lucene "1.23.2"]
18 | [com.xtdb/xtdb-http-server "1.23.2"]]
19 |
20 | :repl-options {:init-ns xtdb-in-a-box.db}
21 |
22 | ;; XTDB SHA1 workaround for JDK 17 on MacOS:
23 | :plugins [[lein-with-env-vars "0.2.0"]]
24 |
25 | ;; logging:
26 | :jvm-opts ["-Dclojure.tools.logging.factory=clojure.tools.logging.impl/slf4j-factory"
27 | ;; the following option is required for JDK 16 and 17:
28 | ;; https://github.com/xtdb/xtdb/issues/1462
29 | "--add-opens=java.base/java.util.concurrent=ALL-UNNAMED"]
30 |
31 | ;; the following implements the XTDB SHA1 workaround for JDK 17 on MacOS:
32 | :hooks [leiningen.with-env-vars/auto-inject]
33 | :env-vars {:XTDB_ENABLE_BYTEUTILS_SHA1 "true"})
34 |
--------------------------------------------------------------------------------
/java/src/main/java/xtdbinabox/Box.java:
--------------------------------------------------------------------------------
1 | package xtdbinabox;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.util.Collection;
6 | import java.util.HashMap;
7 | import java.util.List;
8 |
9 | import xtdb.api.IXtdb;
10 | import xtdb.api.IXtdbDatasource;
11 | import xtdb.api.ICursor;
12 | import xtdb.api.XtdbDocument;
13 | import xtdb.api.TransactionInstant;
14 | import xtdb.api.tx.Transaction;
15 |
16 | class Box {
17 | public static void main(String[] args) {
18 | try (IXtdb node = IXtdb.startNode(new File("config.json"))) {
19 | System.out.println("Xtdb Started.");
20 |
21 | // submitTx example:
22 | HashMap data = new HashMap<>();
23 | data.put("user/name", "zig");
24 | XtdbDocument document = XtdbDocument.create("hi2u", data);
25 | TransactionInstant transaction = node.submitTx(Transaction.buildTx(tx -> {
26 | tx.put(document);
27 | }));
28 | System.out.println(data.toString());
29 |
30 | // query example:
31 | node.awaitTx(transaction, null);
32 | String query = "{:find [e] :where [[e :user/name \"zig\"]]}";
33 | IXtdbDatasource db = node.db();
34 | Collection> results = db.query(query);
35 | for (List l : results) {
36 | System.out.println(l.toString());
37 | }
38 | db.close();
39 | node.close();
40 | }
41 | catch (IOException e) {
42 | // ...
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/java/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.xtdb
5 | xtdbinabox
6 | 0.0.2
7 |
8 |
9 | 11
10 | 11
11 |
12 |
13 |
14 |
15 | com.xtdb
16 | xtdb-core
17 | 1.23.2
18 |
19 |
20 | com.xtdb
21 | xtdb-rocksdb
22 | 1.23.2
23 |
24 |
25 |
26 |
27 | org.clojure
28 | tools.logging
29 | 1.1.0
30 |
31 |
32 | ch.qos.logback
33 | logback-classic
34 | 1.2.3
35 |
36 |
37 | ch.qos.logback
38 | logback-core
39 | 1.2.3
40 |
41 |
42 | org.slf4j
43 | slf4j-api
44 | 1.7.30
45 |
46 |
47 |
48 |
49 | com.xtdb
50 | xtdb-lucene
51 | 1.23.2
52 |
53 |
54 | com.xtdb
55 | xtdb-http-server
56 | 1.23.2
57 |
58 |
59 |
60 |
61 |
62 | clojars
63 | http://clojars.org/repo/
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | org.apache.maven.plugins
72 | maven-compiler-plugin
73 | 3.8.1
74 |
75 |
76 |
77 |
78 |
79 |
80 | maven-assembly-plugin
81 |
82 |
83 |
84 | xtdbinabox.Box
85 |
86 |
87 |
88 | jar-with-dependencies
89 |
90 |
91 |
92 |
93 | make-assembly
94 | package
95 |
96 | single
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------