-
-
Save ouvanous/f046da540656ed17beb509d579ebb27c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app.core | |
(:require [crux.api :as crux] | |
[clojure.java.io :as io]) | |
(:gen-class) | |
(:import [crux.api ICruxAPI])) | |
(defn start-node [storage-dir] | |
(crux/start-node {:crux.node/topology '[crux.standalone/topology | |
crux.kv.rocksdb/kv-store] | |
:crux.standalone/event-log-dir "crux-store/eventlog-1" | |
:crux.kv/db-dir (str (io/file "crux-store" "db"))})) | |
(defonce node (start-node "crux-store")) | |
(defn insert-items | |
[items] | |
(crux/submit-tx | |
node | |
(mapv (fn [item] | |
[:crux.tx/put item]) | |
items))) | |
(defn all | |
[] | |
(crux/q | |
(crux/db node) | |
{:find '[?id] | |
:where '[[?e :crux.db/id ?id]]})) | |
(defn by-status | |
[status] | |
(crux/q | |
(crux/db node) | |
{:find '[?id] | |
:where '[[?e :crux.db/id ?id] | |
[?e :app/status ?st]] | |
:args [{'?st status}]})) | |
(defn cid | |
[idx status] | |
(println idx status) | |
(keyword (str "item-" idx "-" (name status)))) | |
(defn create-items | |
[items status] | |
(insert-items | |
(mapv (fn [idx] | |
{:crux.db/id (cid idx status) | |
:app/status status}) | |
items))) | |
(defn add-drafts | |
[] | |
(create-items (range 5) :draft)) | |
(defn evict | |
[items] | |
(crux/submit-tx | |
node | |
(mapv (fn [item] | |
[:crux.tx/evict item]) | |
items))) | |
(defn add-published | |
[] | |
(let [items (range 3) | |
drafts-id (map (fn [idx] | |
(cid idx :draft)) | |
items)] | |
(create-items items :okok) | |
(evict drafts-id))) | |
(defn set-to-published | |
[]) | |
(defn -main | |
"I don't do a whole lot ... yet." | |
[& args] | |
(println "OK ...") | |
(println (add-drafts)) | |
; (Thread/sleep 500) | |
(println (all)) | |
(println (add-published)) | |
; (Thread/sleep 500) | |
(println (all))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is what is printed for me with
1.9.1
: