   "Delete a `Card`."
   [id]
   (write-check Card id)
-  (let-404 [card (sel :one Card :id id)]
+  (let-404 [card (Card id)]
     (write-check card)
-    (u/prog1 (cascade-delete Card :id id)
+    (u/prog1 (db/cascade-delete! Card id)
       (events/publish-event :card-delete (assoc card :actor_id *current-user-id*)))))
 
 (defendpoint GET "/:id/favorite"
   "Has current user favorited this `Card`?"
   [id]
   {:favorite (boolean (when *current-user-id*
-                        (exists? CardFavorite :card_id, id :owner_id *current-user-id*)))})
+                        (db/exists? CardFavorite :card_id id, :owner_id *current-user-id*)))})
 
 (defendpoint POST "/:card-id/favorite"
   "Favorite a Card."
   [card-id]
-  (ins CardFavorite :card_id card-id, :owner_id *current-user-id*))
+  (db/insert! CardFavorite :card_id card-id, :owner_id *current-user-id*))
 
 (defendpoint DELETE "/:card-id/favorite"
   "Unfavorite a Card."
   [card-id]
-  (let-404 [id (sel :one :id CardFavorite :card_id card-id, :owner_id *current-user-id*)]
-    (del CardFavorite :id id)))
+  (let-404 [id (db/select-one-id CardFavorite :card_id card-id, :owner_id *current-user-id*)]
+    (db/cascade-delete! CardFavorite id)))
 
 (defendpoint POST "/:card-id/labels"
   "Update the set of `Labels` that apply to a `Card`."
   [card-id :as {{:keys [label_ids]} :body}]
   {label_ids [Required ArrayOfIntegers]}
   (write-check Card card-id)
-  (let [[labels-to-remove labels-to-add] (data/diff (set (sel :many :field [CardLabel :label_id] :card_id card-id))
+  (let [[labels-to-remove labels-to-add] (data/diff (set (db/select-field :label_id CardLabel :card_id card-id))
                                                     (set label_ids))]
-    (doseq [label-id labels-to-remove]
-      (cascade-delete CardLabel :label_id label-id, :card_id card-id))
+    (when (seq labels-to-remove)
+      (db/cascade-delete! CardLabel :label_id [:in labels-to-remove], :card_id card-id))
     (doseq [label-id labels-to-add]
-      (ins CardLabel :label_id label-id, :card_id card-id)))
+      (db/insert! CardLabel :label_id label-id, :card_id card-id)))
   ;; TODO - Should this endpoint return something more useful instead ?
   {:status :ok})
 

(ns metabase.api.card
  (:require [clojure.data :as data]
            [compojure.core :refer [GET POST DELETE PUT]]
            [korma.core :as k]
            [metabase.events :as events]
            [metabase.api.common :refer :all]
            [metabase.db :refer :all]
            (metabase.models [hydrate :refer [hydrate]]
                             [card :refer [Card] :as card]
                             [card-favorite :refer [CardFavorite]]

    (checkp (integer? model_id) "id" (format "id is required parameter when filter mode is '%s'" (name f)))
    (case f
      :database (read-check Database model_id)
      :table    (read-check Database (db/select-one-field :db_id Table, :id model_id))))
  (cards-for-filter-option f model_id label))

(defendpoint POST "/"
