Skip to content

Commit

Permalink
Merge pull request #5 from AlexWheeler/use-resultset-seq
Browse files Browse the repository at this point in the history
use clojure.core/resultset-seq over while, .next, .hasNext
  • Loading branch information
AlexWheeler authored Nov 17, 2016
2 parents ddd2aa5 + 9075214 commit e0bcf22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/airlift/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@

(def creds {:host "" :username "" :password ""})

;;(defn -main [& args]
;; (let [chan (ch/channel creds)]
;; (ch/upload chan "hello.txt")))

(defn -main [& args]
(let [conn (db/init "" "" "")
chan (ch/channel creds)]
(doseq [table []]
(let [res (db/query conn (str "SELECT * FROM " table))]
(let [columns (db/columns res) data (atom [])]
(while (.next res)
(swap! data conj (map #(.getString res %) columns)))
(csv/write @data (str table ".csv"))
(ch/upload chan (str table ".csv")))))))
(let [data [] res (db/query conn (str "SELECT * FROM " table))]
(let [headers (->> (first res)
(keys)
(map name)
(vec)
(conj data))
body (->> (rest res)
(map (comp vec vals))
(vec)
(apply conj headers))]
(csv/write body (str table ".csv"))
(ch/upload chan (str table ".csv")))))))
2 changes: 1 addition & 1 deletion src/airlift/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

(defn query [conn query]
"Executes query on db connection and returns ResultSet"
(.. conn (createStatement) (executeQuery query)))
(resultset-seq (.. conn (createStatement) (executeQuery query))))

(defn columns [response]
"Returns vector of table columns"
Expand Down

0 comments on commit e0bcf22

Please sign in to comment.