generated from FiV0/clj-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ingest.clj
38 lines (31 loc) · 1.07 KB
/
ingest.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
(ns xtdb-chinook.ingest
"Ingests that data from the sqlite db into an xt instance."
(:require [clojure.java.io :as io]
[clojure.set]
[xtdb-chinook.export :as export]
[xtdb.api :as xt]))
;; xt
(defn start-xtdb! []
(letfn [(kv-store [dir]
{:kv-store {:xtdb/module 'xtdb.rocksdb/->kv-store
:db-dir (io/file dir)
:sync? true}})]
(xt/start-node
{:xtdb/tx-log (kv-store "data/tx-log")
:xtdb/document-store (kv-store "data/doc-store")
:xtdb/index-store (kv-store "data/index-store")})))
(def xtdb-node (start-xtdb!))
(defn stop-xtdb! [] (.close xtdb-node))
(defn ingest [_]
(xt/submit-tx xtdb-node
(->> (export/chinook-entities export/con)
(map #(clojure.set/rename-keys % {:db/id :xt/id}))
(map #(vector ::xt/put %))
doall))
(xt/sync xtdb-node)
(stop-xtdb!))
(comment
(ingest nil)
(->> (read-string (slurp "entities.edn"))
(map #(clojure.set/rename-keys % {:db/id :xt/id})))
)