Back

make-datasource (clj)

(source)

function

(make-datasource datasource-options)
Make datasource from `datasource-options`

Examples

hikari-cp
(ns hikari-cp.core-test
  (:require [hikari-cp.core :refer :all])
  (:use expectations)
  (:import (com.zaxxer.hikari.pool HikariPool$PoolInitializationException)
           (com.codahale.metrics MetricRegistry)
           (com.codahale.metrics.health HealthCheckRegistry)
           (com.zaxxer.hikari.metrics.prometheus PrometheusMetricsTrackerFactory)))

(expect HikariPool$PoolInitializationException
  (make-datasource valid-options))
kit-clj/kit
(ns kit.edge.db.sql.hikari
  (:require
    [hikari-cp.core :as cp]
    [integrant.core :as ig]
    [kit.ig-utils :as ig-utils]
    ))

(defmethod ig/init-key :db.sql/hikari-connection
  [_ pool-spec]
  (cp/make-datasource pool-spec))
tomekw/hikari-cp
(ns hikari-cp.core-test
  (:require [hikari-cp.core :refer :all])
  (:use expectations)
  (:import (com.zaxxer.hikari.pool HikariPool$PoolInitializationException)
           (com.codahale.metrics MetricRegistry)
           (com.codahale.metrics.health HealthCheckRegistry)
           (com.zaxxer.hikari.metrics.prometheus PrometheusMetricsTrackerFactory)))

(expect HikariPool$PoolInitializationException
  (make-datasource valid-options))
tamizhvendan/honeyeql
(ns core-test
  (:require [clojure.test :refer [deftest testing is run-tests]]
            [honeyeql.core :as heql]
            [honeyeql.db :as heql-db]
            [clojure.edn :as edn]
            [suite-reader :refer [read-string-opts]]
            [hikari-cp.core :as hikari]))

(deftest honeyeql-query-test-suite
  (doseq [[_ {:keys [ds-opts assertions]}]
          (edn/read-string read-string-opts (slurp "./test/suite.edn"))]
    (doseq [{:keys [database-name adapter jdbc-url db-product-name]
             :as   ds-opt} ds-opts]
      (with-open [db-spec (hikari/make-datasource (dissoc ds-opt :db-product-name))]
        (let [db-adapter (heql-db/initialize db-spec)]
          (doseq [{:keys [name eql]} assertions]
            (testing (if (and database-name adapter)
                       (str "Testing " name " on " database-name " in " adapter)
                       (str "Testing " name " on " jdbc-url))
              (let [{:keys [query-single query expected ignore]} eql
                    actual-expected                              (if (vector? expected)
                                                                   (get (apply hash-map expected) db-product-name)
                                                                   expected)]
                (when-not (contains? ignore db-product-name)
                  (if query-single
                    (is (= actual-expected (heql/query-single db-adapter query-single)))
                    (is (= actual-expected (heql/query db-adapter query)))))))))))))
funcool/clojure.jdbc
(ns jdbc.core-tests
  (:import org.postgresql.util.PGobject)
  (:require [jdbc.core :as jdbc]
            [jdbc.proto :as proto]
            [hikari-cp.core :as hikari]
            [cheshire.core :as json]
            [clojure.test :refer :all]))

(deftest datasource-spec
  (with-open [ds (hikari/make-datasource {:adapter "h2" :url "jdbc:h2:/tmp/test"})]
    (is (instance? javax.sql.DataSource ds))
    (with-open [conn (jdbc/connection ds)]
      (let [result (jdbc/fetch conn "SELECT 1 + 1 as foo;")]
        (is (= [{:foo 2}] result))))))
PacktWorkshops/The-Clojure-Workshop
(ns packt-clj.exercises.connection-pooling
  (:require
    [clojure.java.jdbc :as jdbc]
    [hikari-cp.core :as hikari]))

; option 1
(def db {:datasource (hikari/make-datasource {:jdbc-url "jdbc:derby:derby-local;create=true"})})

; option 2
(def db {:datasource
         (hikari/make-datasource {:database-name         "derby-local"
                                  :datasource-class-name "org.apache.derby.jdbc.EmbeddedDataSource"})})