Skip to content

Commit f901d30

Browse files
committed
Add example
1 parent 509049b commit f901d30

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
(ns xtdb.tarantool.example
2+
(:require
3+
[clojure.tools.namespace.repl :as tools.repl]
4+
[integrant.core :as ig]
5+
[integrant.repl :as ig.repl]
6+
[integrant.repl.state :as ig.repl.state]
7+
[xtdb.api :as xt]
8+
[xtdb.tarantool :as tnt])
9+
(:import
10+
(java.io
11+
Closeable)
12+
(java.time
13+
Duration)))
14+
15+
16+
(tools.repl/set-refresh-dirs "src/dev/clojure")
17+
18+
19+
(defn config
20+
[]
21+
{::xtdb-tnt {::tnt-client {:xtdb/module 'xtdb.tarantool/->tnt-client
22+
:username "root"
23+
:password "root"}
24+
:xtdb/tx-log {:xtdb/module 'xtdb.tarantool/->tx-log
25+
:tnt-client ::tnt-client
26+
:poll-wait-duration (Duration/ofSeconds 5)}
27+
:xtdb.http-server/server {:read-only? true
28+
:server-label "[xtdb-tarantool] Console Demo"}}})
29+
30+
31+
(defn prep
32+
[]
33+
(ig.repl/set-prep! config))
34+
35+
36+
(defn go
37+
[]
38+
(prep)
39+
(ig.repl/go))
40+
41+
42+
(def halt ig.repl/halt)
43+
(def reset-all ig.repl/reset-all)
44+
45+
46+
(defn system
47+
[]
48+
ig.repl.state/system)
49+
50+
51+
(defmethod ig/init-key ::xtdb-tnt [_ config]
52+
(xt/start-node config))
53+
54+
55+
(defmethod ig/halt-key! ::xtdb-tnt [_ ^Closeable node]
56+
(tnt/close node))
57+
58+
59+
(comment
60+
61+
(reset-all)
62+
(halt)
63+
(go)
64+
;; open http://localhost:3000/
65+
66+
67+
(def node
68+
(::xtdb-tnt (system)))
69+
70+
(xt/submit-tx node [[::xt/put {:xt/id "xtdb-tarantool", :user/email "ilshat@sultanov.team"}]])
71+
;; => #:xtdb.api{:tx-id 1, :tx-time #inst"2021-12-04T01:27:15.641-00:00"}
72+
73+
74+
(xt/q (xt/db node) '{:find [e]
75+
:where [[e :user/email "ilshat@sultanov.team"]]})
76+
;; => #{["xtdb-tarantool"]}
77+
78+
79+
(xt/q (xt/db node)
80+
'{:find [(pull ?e [*])]
81+
:where [[?e :xt/id "xtdb-tarantool"]]})
82+
;; => #{[{:user/email "ilshat@sultanov.team", :xt/id "xtdb-tarantool"}]}
83+
84+
85+
86+
(def history (xt/entity-history (xt/db node) "xtdb-tarantool" :desc {:with-docs? true}))
87+
;; => [#:xtdb.api{:tx-time #inst"2021-12-04T01:31:14.080-00:00",
88+
;; :tx-id 2,
89+
;; :valid-time #inst"2021-12-04T01:31:14.080-00:00",
90+
;; :content-hash #xtdb/id"d0eb040d39fbdaa8699d867bc9fb9aa244b8e154",
91+
;; :doc {:user/email "ilshat@sultanov.team", :xt/id "xtdb-tarantool"}}]
92+
93+
94+
(->> (map ::xt/doc history)
95+
(filterv (comp (partial = "ilshat@sultanov.team") :user/email)))
96+
;; => [{:user/email "ilshat@sultanov.team", :xt/id "xtdb-tarantool"}]
97+
)

0 commit comments

Comments
 (0)