       (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)

    :database_id database))


(defendpoint POST "/" [:as {{:keys [clone] :as body} :body}]
  {clone Integer}
  (if clone
    (query-clone clone)
    (query-create body)))


(defendpoint GET "/:id" [id]
  (->404 (sel :one Query :id id)
         read-check
         (hydrate :creator :database :can_read :can_write)))


(defendpoint PUT "/:id" [id :as {{:keys [name public_perms details timezone database] :as body} :body}]
  {database     [Required Dict]
   name         NonEmptyString
   public_perms PublicPerms}

        (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)
