                  :query-params params}]
     (execute @(http/delete url options))))
 
-(defn- get-doc
-  [id]
-  (get (str "/swarmpit/" id)))
-
-(defn- create-doc
+(defn get-doc
+  [id]
+  (try
+    (get (str "/swarmpit/" id))
+    (catch Exception _)))
+
+(defn create-doc
   [doc]
   (post "/swarmpit" doc))
 
-(defn- find-doc
+(defn find-docs
+  ([type]
+   (find-docs nil type))
+  ([query type]
+   (->> {:selector (merge query {:type {"$eq" type}})}
+        (post "/swarmpit/_find")
+        :docs)))
+
+(defn find-doc
   [query type]
-  (->> {:selector (merge query {:type {"$eq" type}})}
-       (post "/swarmpit/_find")
-       :docs
-       (first)))
-
-(defn- find-all-docs
-  [type]
-  (->> {:selector {:type {"$eq" type}}}
-       (post "/swarmpit/_find")
-       :docs))
-
-(defn- delete-doc
+  (first (find-docs query type)))
+
+(defn delete-doc
   [doc]
   (let [url (str "/swarmpit/" (:_id doc))]
     (delete url {:rev (:_rev doc)})))
 
-(defn- update-doc
+(defn update-doc
   ([doc delta]
    (let [url (str "/swarmpit/" (:_id doc))]
      (put url (merge doc delta))))


(defn users
  []
  (find-all-docs "user"))

(defn user
  [id]


;; Docker user

(defn dockerusers
  [owner]
  (find-docs {"$or" [{:owner {"$eq" owner}}
                     {:public {"$eq" true}}]} "dockeruser"))

(defn dockeruser
  [id]
  (get-doc id))

(defn dockeruser-exist?
  [docker-user]
  (some? (find-doc {:username {"$eq" (:username docker-user)}
                    :owner    {"$eq" (:owner docker-user)}} "dockeruser")))

(defn dockeruser-by-name
  [username]
  (find-doc {:username {"$eq" username}} "dockeruser"))

(defn create-dockeruser
  [docker-user]
  (create-doc docker-user))

(defn delete-dockeruser
  [docker-user]
  (delete-doc docker-user))

;; Registry

(defn registries
  [owner]
  (find-docs {"$or" [{:owner {"$eq" owner}}
                     {:public {"$eq" true}}]} "registry"))

(defn registry
  [id]
  (get-doc id))

(defn registry-exist?
  [registry]
  (some? (find-doc {:name  {"$eq" (:name registry)}
                    :owner {"$eq" (:owner registry)}} "registry")))

(defn registry-by-name
  [name owner]
  (find-doc {:name  {"$eq" name}
             :owner {"$eq" owner}} "registry"))

(defn create-registry
  [registry]
