Back

uri->db-spec (clj)

(source)

function

(uri->db-spec uri)
clojure.java.jdbc (and some users out there) considered the URI format to be an acceptable JDBC URL, i.e., with credentials embdedded in the string, rather than as query parameters. This function accepts a URI string, optionally prefixed with `jdbc:` and returns a db-spec hash map.

Examples

next-jdbc
  At some point, the datasource/connection tests should probably be extended
  to accept EDN specs from an external source (environment variables?)."
  (:require [clojure.string :as str]
            [clojure.test :refer [deftest is testing]]
            [next.jdbc.connection :as c]
            [next.jdbc.protocols :as p])
  (:import (com.zaxxer.hikari HikariDataSource)
           (com.mchange.v2.c3p0 ComboPooledDataSource PooledDataSource)))

(deftest issue-243-uri->db-spec
  (is (= {:dbtype "mysql" :dbname "mydb"
          :host "myserver" :port 1234
          :user "foo" :password "bar"}
         (c/uri->db-spec "mysql://foo:bar@myserver:1234/mydb")))
  (is (= {:dbtype "mysql" :dbname "mydb"
          :host "myserver" :port 1234
          :user "foo" :password "bar"}
         (c/uri->db-spec "jdbc:mysql://myserver:1234/mydb?user=foo&password=bar"))))
seancorfield/next-jdbc
  At some point, the datasource/connection tests should probably be extended
  to accept EDN specs from an external source (environment variables?)."
  (:require [clojure.string :as str]
            [clojure.test :refer [deftest is testing]]
            [next.jdbc.connection :as c]
            [next.jdbc.protocols :as p])
  (:import (com.zaxxer.hikari HikariDataSource)
           (com.mchange.v2.c3p0 ComboPooledDataSource PooledDataSource)))

(deftest issue-243-uri->db-spec
  (is (= {:dbtype "mysql" :dbname "mydb"
          :host "myserver" :port 1234
          :user "foo" :password "bar"}
         (c/uri->db-spec "mysql://foo:bar@myserver:1234/mydb")))
  (is (= {:dbtype "mysql" :dbname "mydb"
          :host "myserver" :port 1234
          :user "foo" :password "bar"}
         (c/uri->db-spec "jdbc:mysql://myserver:1234/mydb?user=foo&password=bar"))))