 ;; RethinkDB usage
 (def conn2 [:host "127.0.0.1" :port 28015 :db "open_company"])
 
+;; Get a company
 (aprint (with-open [c (apply r/connect conn2)]
   (-> (r/table "companies")
       (r/get "buffer")
       (r/run c))))
 
+;; Update the sections in a company
 (with-open [c (apply r/connect conn2)]
   (-> (r/table "companies")
       (r/get "open")

        (r/without company [{:competition {:icon true}}])))
      (r/run c)))

(aprint (with-open [c (apply r/connect conn2)]
  (-> (r/table "sections")
    (r/get-all ["buffer"] {:index "company-slug"})
    (r/run c))))

(aprint (with-open [c (apply r/connect conn2)]
  (-> (r/table "sections")
    (r/get-all [["green-labs" "update"]] {:index "company-slug-section-name"})
    (r/run c))))

(with-open [c (apply r/connect conn2)]
  (-> (r/table "sections")
    (r/get-all [["open" "finances"]] {:index "company-slug-section-name"})
    (r/delete)
    (r/run c)))

(with-open [c (apply r/connect conn2)]
  (-> (r/table "sections")
    (r/replace (r/fn [section]
      (r/without section [:core])))
    (r/run c)))

(aprint (with-open [c (apply r/connect conn2)]
  (-> (r/table "sections")
    (r/get-all ["21c9ddd4-6d1c-47a5-b6c1-1308fed08523"] {:index "id"})
    (r/run c))))

(with-open [c (apply r/connect conn2)]
  (-> (r/table "companies")
      (r/get "open")
      (r/update {:update {:body "<p>It's time to learn. That's it, really. Put it in the hands of people we admire and trust, and <b>LEARN FAST</b>.</p><p><img src=\"https://cdn.filestackcontent.com/ge9NSlJTP2AXfwl0nGvk\" data-height=\"370\" data-width=\"555\"><br></p><p><br></p>"}})
      (r/run c)))

;; Provide a new slug for a company
(with-open [c (apply r/connect conn2)]

(with-open [c (apply r/connect conn2)]
  (-> (r/table "companies")
      (r/get "open")
      (r/replace (r/fn [company]
        (r/without company [:mission])))
      (r/run c)))

;; Empty out the stakeholder update template
(with-open [c (apply r/connect conn2)]
  (-> (r/table "companies")
      (r/get "open")
      (r/update {:stakeholder-update (r/literal {:title "" :sections []})})
      (r/run c)))

;; Mark a company as public/private
(with-open [c (apply r/connect conn2)]
  (-> (r/table "companies")
      (r/get "startup-city")
      (r/update {:public true})
      (r/run c)))

;; Remove a sub-property of a topic from a company
(with-open [c (apply r/connect conn2)]
  (-> (r/table "companies")
      (r/get "startup-city")
