-
Notifications
You must be signed in to change notification settings - Fork 0
/
xtdb.clj
53 lines (46 loc) · 1.66 KB
/
xtdb.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(ns xtdb
(:require
[daba.api :as db]
[portal.api :as p]
[xtdb.api :as xt]))
(comment
;; Open Portal window with Daba extensions and set up tap>
(do
(def p (db/open))
(add-tap #'db/submit))
;; Close the window and remove tap>
(do
(remove-tap #'db/submit)
(p/close))
(def connection-args
(let [base-dir "tmp/xtdb-dev"
kv-store (fn [dir] {:kv-store {:xtdb/module 'xtdb.rocksdb/->kv-store
:db-dir (str base-dir dir)
:sync? true}})]
{:xtdb/tx-log (kv-store "/tx-log")
:xtdb/document-store (kv-store "/doc-store")
:xtdb/index-store (kv-store "/index-store")}))
(def movies-data [{:movie/title "The Goonies"
:movie/genre "action/adventure"
:movie/release-year 1985
:xt/id 1}
{:movie/title "Commando"
:movie/genre "thriller/action"
:movie/release-year 1985
:xt/id 2}
{:movie/title "Repo Man"
:movie/genre "punk dystopia"
:movie/release-year 1984
:xt/id 3}])
;; Insert sample data
(with-open [xtdb-node (xt/start-node connection-args)]
(xt/submit-tx xtdb-node (for [doc movies-data]
[:xtdb.api/put doc]))
(xt/sync xtdb-node))
;; Open connection for inspection
(db/inspect connection-args)
;; Querying manually
(with-open [xtdb-node (xt/start-node connection-args)]
(xt/q (xt/db xtdb-node)
'{:find [title]
:where [[_ :movie/title title]]})))