 (ns cljspazzer.db.schema
-  (:require [clojure.java.jdbc :as sql]))
+  (:require [clojure.java.jdbc :as sql]
+            [clojure.java.io :as io]))
 
 (def the-db {:classname "org.sqlite.JDBC",
              :subprotocol "sqlite",


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

                                           r (hash-map k v)]
                                       r)) rows))]
    result))

(defn prune-tracks
  "get rid of rows where the files no longer exist"
  [db]
  (let [files (filter (fn [f] (not (.exists f))) (map io/file (keys (last-modified-index db))))]
    (map (partial delete-track! db) (map (fn [f] (.getAbsolutePath f)) files))))
