|
| 1 | +(ns db |
| 2 | + (:require [clojure.java.io :as io] |
| 3 | + [xtdb.api :as xt])) |
| 4 | + |
| 5 | + |
| 6 | +(def xtdb-node) |
| 7 | + |
| 8 | +(defn start-xtdb! [] |
| 9 | + (letfn [(kv-store [dir] |
| 10 | + {:kv-store {:xtdb/module 'xtdb.rocksdb/->kv-store |
| 11 | + :db-dir (io/file dir) |
| 12 | + :sync? true}})] |
| 13 | + ;; This env var relates to these issues when running on a Mac (which I do) |
| 14 | + ;; https://github.com/xtdb/xtdb-in-a-box/blob/d7d56f546e6c63565709bbfd8fc3f97499a4f846/java/Makefile#L7 |
| 15 | + ;; https://github.com/xtdb/xtdb/blob/e2f51ed99fc2716faa8ad254c0b18166c937b134/core/src/xtdb/hash.clj#L12 |
| 16 | + ;; And is somewhat related to |
| 17 | + ;; https://github.com/xtdb/xtdb/issues/1518 |
| 18 | + (def xtdb-node (xt/start-node |
| 19 | + {:xtdb/tx-log (kv-store "data/dev/tx-log") |
| 20 | + :xtdb/document-store (kv-store "data/dev/doc-store") |
| 21 | + :xtdb/index-store (kv-store "data/dev/index-store")})))) |
| 22 | + |
| 23 | +(defn stop-xtdb! [] |
| 24 | + (.close xtdb-node)) |
| 25 | + |
| 26 | +(defn q [query & args] |
| 27 | + (apply xt/q (xt/db xtdb-node) query args)) |
| 28 | + |
| 29 | + |
| 30 | +(defn load-artifacts! [] |
| 31 | + (let [artifacts [ |
| 32 | + { |
| 33 | + :xt/id 0 |
| 34 | + :spdx/document-id "abc123" |
| 35 | + :spdx/version "SPDX-2.2" |
| 36 | + :spdx/document-name "Document for Product A" |
| 37 | + :spdx/document-namespace "https://github.com/MitchellJThomas/clojure-practice/clj/xtdb" |
| 38 | + :spdx/package-name "Package A" |
| 39 | + } |
| 40 | + ]] |
| 41 | + (xt/submit-tx xtdb-node (for [doc artifacts] [::xt/put doc])) |
| 42 | + (xt/sync xtdb-node)) |
| 43 | +) |
| 44 | + |
| 45 | +(defn load-peeps! [] |
| 46 | + (let [peeps [{ |
| 47 | + :xt/id -1 |
| 48 | + :name "Tracy Anderson" |
| 49 | + :role :senor-director |
| 50 | + :group :integrations |
| 51 | + :department :rnd |
| 52 | + :company :help-systems |
| 53 | + } |
| 54 | + { |
| 55 | + :xt/id -2 |
| 56 | + :name "Matt Bresnan" |
| 57 | + :role :executive-vice-president |
| 58 | + :department :rnd |
| 59 | + :company :help-systems |
| 60 | + :reports-to -20 |
| 61 | + }, |
| 62 | + { |
| 63 | + :xt/id -3 |
| 64 | + :name "Andrew Wagner" |
| 65 | + :role :vice-president |
| 66 | + :department :rnd |
| 67 | + :reports-to -5 |
| 68 | + :company :tripwire |
| 69 | + }, |
| 70 | + { |
| 71 | + :xt/id -4 |
| 72 | + :name "Mitch Thomas" |
| 73 | + :role :senior-architect |
| 74 | + :department :rnd |
| 75 | + :reports-to -3 |
| 76 | + :company :tripwire |
| 77 | + }, |
| 78 | + { |
| 79 | + :xt/id -5 |
| 80 | + :name "Subhajit Bagshee" |
| 81 | + :role :president |
| 82 | + :company :tripwire |
| 83 | + }, |
| 84 | + { |
| 85 | + :xt/id -6 |
| 86 | + :name "Matt Reynolds" |
| 87 | + :role :architect |
| 88 | + :department :rnd |
| 89 | + :reports-to -4 |
| 90 | + :company :tripwire |
| 91 | + }, |
| 92 | + { |
| 93 | + :xt/id -7 |
| 94 | + :name "Andrew Graham" |
| 95 | + :role :architect |
| 96 | + :department :rnd |
| 97 | + :reports-to -4 |
| 98 | + :company :tripwire |
| 99 | + }, |
| 100 | + { |
| 101 | + :xt/id -8 |
| 102 | + :name "Nathan Stoltenberg" |
| 103 | + :role :intern |
| 104 | + :department :rnd |
| 105 | + :reports-to -4 |
| 106 | + :company :tripwire |
| 107 | + }, |
| 108 | + { |
| 109 | + :xt/id -9 |
| 110 | + :name "Adam Simantel" |
| 111 | + :role :manager |
| 112 | + :department :rnd |
| 113 | + :reports-to -3 |
| 114 | + :company :tripwire |
| 115 | + }, |
| 116 | + { |
| 117 | + :xt/id -10, |
| 118 | + :name "Yung" |
| 119 | + :role :manager |
| 120 | + :department :rnd |
| 121 | + :reports-to -9 |
| 122 | + :company :tripwire |
| 123 | + }, |
| 124 | + { |
| 125 | + :xt/id -11, |
| 126 | + :name "Johnny" |
| 127 | + :role :ux-designer |
| 128 | + :department :rnd |
| 129 | + :reports-to -10 |
| 130 | + :company :tripwire |
| 131 | + }, |
| 132 | + { |
| 133 | + :xt/id -12, |
| 134 | + :name "Andrew" |
| 135 | + :role :ux-researcher |
| 136 | + :department :rnd |
| 137 | + :reports-to -10 |
| 138 | + :company :tripwire |
| 139 | + }, |
| 140 | + { |
| 141 | + :xt/id -13, |
| 142 | + :name "Jodah" |
| 143 | + :role :ux-designer |
| 144 | + :department :rnd |
| 145 | + :reports-to -10 |
| 146 | + :company :tripwire |
| 147 | + }, |
| 148 | + { |
| 149 | + :xt/id -14, |
| 150 | + :name "Guy" |
| 151 | + :role :principle-software-engineer |
| 152 | + :department :rnd |
| 153 | + :reports-to -9 |
| 154 | + :company :tripwire |
| 155 | + }, |
| 156 | + { |
| 157 | + :xt/id -15, |
| 158 | + :name "Chris Wilkins" |
| 159 | + :role :senior-technical-writer |
| 160 | + :department :rnd |
| 161 | + :reports-to -9 |
| 162 | + :company :tripwire |
| 163 | + }, |
| 164 | + { |
| 165 | + :xt/id -16, |
| 166 | + :name "Tracy Anderson" |
| 167 | + :role :director |
| 168 | + :department :rnd |
| 169 | + :company :help-systems |
| 170 | + :reports-to -2 |
| 171 | + }, |
| 172 | + { |
| 173 | + :xt/id -17, |
| 174 | + :name "Erick Lichtas" |
| 175 | + :role :associate-director |
| 176 | + :department :architecture |
| 177 | + :company :help-systems |
| 178 | + :reports-to -22 |
| 179 | + }, |
| 180 | + { |
| 181 | + :xt/id -18, |
| 182 | + :name "Bob Erdman" |
| 183 | + :role :manager |
| 184 | + :department :rnd |
| 185 | + :company :help-systems |
| 186 | + :reports-to -16 |
| 187 | + :notes "Data loke" |
| 188 | + }, |
| 189 | + { |
| 190 | + :xt/id -19, |
| 191 | + :name "Alfredo Rodriguez" |
| 192 | + :role :associate-vice-president |
| 193 | + :department :mergeers-and-acquisitions |
| 194 | + :company :help-systems |
| 195 | + :reports-to -20 |
| 196 | + }, |
| 197 | + { |
| 198 | + :xt/id -20, |
| 199 | + :name "John Grancarich" |
| 200 | + :role :executive-vice-president |
| 201 | + :department :product-management |
| 202 | + :company :help-systems |
| 203 | + :reports-to -20 |
| 204 | + }, |
| 205 | + { |
| 206 | + :xt/id -21, |
| 207 | + :name "Kate Bolseth" |
| 208 | + :role :ceo |
| 209 | + :company :help-systems |
| 210 | + }, |
| 211 | + { |
| 212 | + :xt/id -22, |
| 213 | + :name "Steve Luebbe" |
| 214 | + :role :cheif-architect |
| 215 | + :company :help-systems |
| 216 | + :department :architecture |
| 217 | + :business-unit :none |
| 218 | + :reports-to -2 |
| 219 | + }, |
| 220 | + { |
| 221 | + :xt/id -23, |
| 222 | + :name "Joel Cruise" |
| 223 | + :role :qa-director |
| 224 | + :company :help-systems |
| 225 | + :department :rnd |
| 226 | + :reports-to -16 |
| 227 | + }, |
| 228 | + { |
| 229 | + :xt/id -24, |
| 230 | + :name "Mark Young" |
| 231 | + :role :ux-manager |
| 232 | + :company :help-systems |
| 233 | + :department :rnd |
| 234 | + :reports-to -16 |
| 235 | + }, |
| 236 | + { |
| 237 | + :xt/id -25, |
| 238 | + :name "Johnathan Strom" |
| 239 | + :role :qa |
| 240 | + :company :help-systems |
| 241 | + :department :rnd |
| 242 | + :reports-to -22 |
| 243 | + }, |
| 244 | + |
| 245 | + ]] |
| 246 | + (xt/submit-tx xtdb-node (for [doc peeps] [::xt/put doc])) |
| 247 | + (xt/sync xtdb-node) |
| 248 | + ) |
| 249 | + ) |
| 250 | + |
| 251 | +(comment |
| 252 | + ;; use C-q to stop smartparents from creating paired quote |
| 253 | + |
| 254 | + (start-xtdb!) |
| 255 | + |
| 256 | + (load-peeps!) |
| 257 | + |
| 258 | + ;; All entites by id |
| 259 | + (= (q '{:find [id] :where [[_ :xt/id id]]}) |
| 260 | + (q '{:find [e] :where [[e :xt/id]]}) |
| 261 | + ) |
| 262 | + |
| 263 | + ;; Two level of direct reports starting and Andrew W. |
| 264 | + (q '{:find [name1 name2] |
| 265 | + :in [boss-name] |
| 266 | + :where [[e :name name1] |
| 267 | + [b2 :name name2] |
| 268 | + [e :reports-to b2] |
| 269 | + [b2 :reports-to b1] |
| 270 | + [b1 :name boss-name]] } |
| 271 | + "Andrew Wagner") |
| 272 | + |
| 273 | + (q '{:find [name1 name2] |
| 274 | + :in [boss-name] |
| 275 | + :where [[e1 :name name1] |
| 276 | + [e2 :name name2] |
| 277 | + [e1 :reports-to e2] |
| 278 | + [e2 :reports-to e3] |
| 279 | + [e3 :name boss-name]] } |
| 280 | + "Subhajit Bagshee") |
| 281 | + |
| 282 | + (q '{:find [name] :where [[e :name name] |
| 283 | + [e :company #{:tripwire :cisco}] |
| 284 | + [e :department :rnd]]}) |
| 285 | + |
| 286 | + ) |
0 commit comments