 
 (def tables {:tracks {:name "tracks"
                       :columns[[:id :integer "PRIMARY KEY" "AUTOINCREMENT"]
-                               [:path :string]
+                               [:path :string "UNIQUE"]
                                [:title :string]
                                [:artist :string]
                                [:year :string]

(ns cljspazzer.db.schema
  (:require [clojure.java.jdbc :as sql]))

(def the-db {:classname "org.sqlite.JDBC",
             :subprotocol "sqlite",

       (sql/query db ["select count(id) as count from tracks where path=?" t])))
     0))

(defn update-track!
  "returns count of rows affected"
  [db track-info]
  (first (sql/update! db :tracks track-info ["path=?" (:path track-info)])))

(defn insert-track!
  "returns last row id which should correspond to id"
  [db track-info]
  ((keyword "last_insert_rowid()") (first (sql/insert! db :tracks track-info))))

(defn delete-track!
  "returns rows effected which should be > 1 if successful"
  [db path]
  (first (sql/delete! db :tracks ["path=?" path])))

(defn upsert-track!
  "returns {id:??}for intert or {row-count:??} for update"
  [db track-info]
  (let [update-result (update-track! db track-info)]
    (if (> update-result 0)
      {:row-count update-result :action :update}
      {:id (insert-track! db track-info) :action :insert})))


(defn last-modified-index
  "{path:last_modified}"
