Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/pine/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@
{:connection-id ""
:version version}})))

(defn get-connections []
{:result
{:version version
:selected-connection-id @db/connection-id
:connections (connections/list-connections)}})

(defn test-connection [id]
(let [result (db/run-query id {:query "SELECT NOW();"})]
{:connection-id id :time result}))
Expand Down Expand Up @@ -171,7 +177,7 @@
(defroutes app-routes
;; connection management
(GET "/api/v1/connection" [] (-> (get-connection) response))
(GET "/api/v1/connections" [] (-> @connections/pools response))
(GET "/api/v1/connections" [] (-> (get-connections) response))
(POST "/api/v1/connections" req
(let [connection (get-in req [:params])]
(-> {:connection-id (connections/add-connection-pool connection)} response)))
Expand Down
15 changes: 15 additions & 0 deletions src/pine/db/connections.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,24 @@
(defn make-connection-id [pool]
(-> pool .getJdbcUrl (s/split #"/") (nth 2)))

(defn jdbc-url->label [url]
(let [parts (s/split url #"/")
host-port (nth parts 2)
dbname (nth parts 3)]
(str host-port " · " dbname)))

(defn make-connection-label [pool]
(jdbc-url->label (.getJdbcUrl pool)))

(defn get-connection-name [id]
(-> id get-connection-pool make-connection-id))

(defn list-connections []
(mapv (fn [[id _]]
{:id id
:label (make-connection-label (get-connection-pool id))})
@pools))

(defn add-connection-pool [connection]
(let [pool (create-pool connection)
id (make-connection-id pool)]
Expand Down
Loading