         (hydrate :creator :database))))
 
 
-(defendpoint DELETE "/:id" [id]
+(defendpoint DELETE "/:id"
+  "Delete a `Query`."
+  [id]
   (write-check Query id)
   (del Query :id id))
 
 
-(defendpoint POST "/:id" [id]
+(defendpoint POST "/:id"
+  "Execute a `Query` asynchronously."
+  [id]
   (let-404 [{database-id :database_id
              {:keys [sql timezone]} :details :as query} (sel :one Query :id id)]
     (read-check query)

      (driver/dataset-query dataset-query options))))


(defendpoint GET "/:id/results" [id]
  (read-check Query id)
  (sel :many QueryExecution :query_id id (order :finished_at :DESC) (limit 10)))

(defendpoint GET "/:id/csv" [id]
  (let-404 [{{:keys [columns rows]} :result_data :as query-execution} (sel :one all-fields, :query_id id, (order :started_at :DESC))]
    (let-404 [{{:keys [can_read name]} :query} (hydrate query-execution :query)]
      (check-403 @can_read)

   :databases   (databases-for-org org)})


(defendpoint GET "/"
  "Fetch all `Querys` for an `Org`. With filter option F (default `all`), return all queries;
   with `mine`, only return queries created by the current user."
  [org f]
  {org Required, f FilterOptionAllOrMine}
  (read-check Org org)
  (-> (case (or f :all)
        :all (sel :many Query
                  (where (or (= :creator_id *current-user-id*) (> :public_perms common/perms-none)))
               (where {:database_id [in (subselect Database (fields :id) (where {:organization_id org}))]})
