       (driver/dataset-query dataset-query options))))
 
 
-(defendpoint GET "/:id/results" [id]
+(defendpoint GET "/:id/results"
+  "Fetch the most recent results of a `Query`."
+  [id]
   (read-check Query id)
   (sel :many QueryExecution :query_id id (order :finished_at :DESC) (limit 10)))
 
-(defendpoint GET "/:id/csv" [id]
+(defendpoint GET "/:id/csv"
+  "Fetch the most recent results of a `Query` as 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 "/" [org f]
  {org Required, f FilterOptionAllOrMine}
  (read-check Org org)
  (-> (case (or f :all) ; default value for `f` is `: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}))]})

        (hydrate :creator :database))))


(defendpoint DELETE "/:id"
  "Delete a `Query`."
  [id]
  (write-check Query id)
  (del Query :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)
