This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
REPL_notes.clj
92 lines (79 loc) · 3.26 KB
/
REPL_notes.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;; productive set of development namespaces (Clojure API)
(require '[rethinkdb.query :as r])
(require '[schema.core :as schema])
(require '[oc.storage.config :as config])
(require '[oc.lib.db.pool :as pool])
(require '[oc.lib.slugify :as slug])
(require '[oc.lib.db.common :as db-common])
(require '[oc.storage.resources.common :as common] :reload)
(require '[oc.storage.resources.org :as org] :reload)
(require '[oc.storage.resources.board :as board] :reload)
(require '[oc.storage.resources.entry :as entry] :reload)
;; productive set of development namespaces (REST API)
(require '[cheshire.core :as json])
(require '[ring.mock.request :refer (request body content-type header)])
(require '[open-company.lib.rest-api-mock :refer (api-request)] :reload)
(require '[oc.storage.app :refer (app)] :reload)
(require '[oc.lib.api.common :as api-common])
(require '[oc.storage.api.access :as access] :reload)
(require '[oc.storage.api.entry-point :as entry-point-api] :reload)
(require '[oc.storage.api.orgs :as orgs-api] :reload)
(require '[oc.storage.api.activity :as activity-api] :reload)
(require '[oc.storage.api.boards :as boards-api] :reload)
(require '[oc.storage.api.entries :as entries-api] :reload)
(require '[oc.storage.representations.media-types :as mt] :reload)
(require '[oc.storage.representations.org :as org-rep] :reload)
(require '[oc.storage.representations.board :as board-rep] :reload)
(require '[oc.storage.representations.entry :as entry-rep] :reload)
;; make a (fake) REST API request
(api-request :get "/orgs/buffer" {:headers {:Accept (company-rep/media-type)}})
;; print last exception
(print-stack-trace *e)
;; Validate sections in sections.edn against schema (should be all nils)
(def sections*
(->> common/sections (map #(assoc % :company-slug "x"))))
(map #(schema/check common/Section %) sections*)
;; RethinkDB usage
(def conn2 [:host "127.0.0.1" :port 28015 :db "open_company_storage"])
;; Get an org
(aprint (with-open [c (apply r/connect conn2)]
(-> (r/table "orgs")
(r/get "buffer")
(r/run c))))
;; Get orgs by team ID
(aprint (with-open [c (apply r/connect conn2)]
(-> (r/table "orgs")
(r/get-all ["51ab-4c86-a477"] {:index :team-id})
(r/run c))))
;; Get orgs by team ID
(aprint (with-open [c (apply r/connect conn2)]
(-> (r/table "orgs")
(r/get-all ["51ab-4c86-a477"] {:index :team-id})
(r/run c))))
;; Get orgs by team IDs
(aprint (with-open [c (apply r/connect conn2)]
(-> (r/table "orgs")
(r/get-all ["51ab-4c86-a474" "51ab-4c86-a477"] {:index :team-id})
(r/run c))))
;; Get all the entries for a company
(aprint (with-open [c (apply r/connect conn2)]
(-> (r/table "entries")
(r/get-all ["buffer"] {:index "company-slug"})
(r/run c))))
;; Remove a property from all entries
(with-open [c (apply r/connect conn2)]
(-> (r/table "entries")
(r/replace (r/fn [e]
(r/without e [:data :intervals :metrics :units :prompt])))
(r/run c)))
;; Update a property in an entry
(with-open [c (apply r/connect conn2)]
(-> (r/table "entries")
(r/get "b0d3-4072-954e")
(r/update (r/fn [e]
{:published-at "2017-10-27T19:12:40.644Z"}))
(r/run c)))
;; for more RethinkDB help, see:
;; https://github.com/apa512/clj-rethinkdb
;; http://apa512.github.io/clj-rethinkdb/
;; https://rethinkdb.com/api/python/