Skip to content
Snippets Groups Projects
Commit 064bc6e3 authored by Cam Saül's avatar Cam Saül
Browse files

Support postgresql:// db connection URLs

parent a1ff9479
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,10 @@
"Parse a DB connection URI like `postgres://cam@localhost.com:5432/cams_cool_db?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory` and return a broken-out map."
[uri]
(when-let [[_ protocol user pass host port db query] (re-matches #"^([^:/@]+)://(?:([^:/@]+)(?::([^:@]+))?@)?([^:@]+)(?::(\d+))?/([^/?]+)(?:\?(.*))?$" uri)]
(merge {:type (keyword protocol)
(merge {:type (case (keyword protocol)
:postgres :postgres
:postgresql :postgres
:mysql :mysql)
:user user
:password pass
:host host
......
......@@ -6,11 +6,18 @@
(tu/resolve-private-vars metabase.db parse-connection-string)
;; parse minimal connection string
(expect {:type :postgres :user nil :password nil :host "localhost" :port nil :dbname "toms_cool_db" }
(expect
{:type :postgres, :user nil, :password nil, :host "localhost", :port nil, :dbname "toms_cool_db" }
(parse-connection-string "postgres://localhost/toms_cool_db"))
;; parse connection string using alternate `postgreql` URI schema
(expect
{:type :postgres, :user nil, :password nil, :host "localhost", :port nil, :dbname "toms_cool_db" }
(parse-connection-string "postgresql://localhost/toms_cool_db"))
;; parse all fields and query string arguments
(expect {:type :postgres :user "tom" :password "1234" :host "localhost" :port "5432" :dbname "toms_cool_db" :ssl "true" :sslfactory "org.postgresql.ssl.NonValidatingFactory"}
(expect
{:type :postgres, :user "tom", :password "1234", :host "localhost", :port "5432", :dbname "toms_cool_db", :ssl "true", :sslfactory "org.postgresql.ssl.NonValidatingFactory"}
(parse-connection-string "postgres://tom:1234@localhost:5432/toms_cool_db?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment