Work with databases (DB) / Connect to the DB

;; This sandbox carries no JDBC driver and no network, so a real file
;; cannot be opened. What a connection gives you, though, is a source of
;; rows - and in Clojure rows are ordinary maps, from wherever they came
(def rows
  [{:language "Russian"   :percentage 86.6}
   {:language "Tatar"     :percentage 3.2}
   {:language "Ukrainian" :percentage 1.3}])

;; select language, percentage from countrylanguage
;; where code = 'RUS' order by percentage desc
(doseq [r (sort-by :percentage > rows)]
  (println (:language r) ":" (:percentage r)))

;; with next.jdbc on the classpath a SQLite file opens in one line,
;; and every row arrives as exactly such a map:
;; (def ds (jdbc/get-datasource {:dbtype "sqlite" :dbname "data.sqlite"}))
;; (jdbc/execute! ds ["select language, percentage from countrylanguage"])