-
Notifications
You must be signed in to change notification settings - Fork 0
/
embedded_postgres_impl.clj
36 lines (27 loc) · 993 Bytes
/
embedded_postgres_impl.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(ns andrewslai.clj.persistence.rdbms.embedded-postgres-impl
(:require [andrewslai.clj.persistence.rdbms.embedded-db-utils :as edb-utils])
(:import io.zonky.test.db.postgres.embedded.EmbeddedPostgres))
(defn ->db-spec
[embedded-db]
{:classname "org.postgresql.Driver"
:subprotocol "postgresql"
:subname (format "//localhost:%s/postgres" (.getPort embedded-db))
:user "postgres"})
(defn start-db!
[]
(->db-spec (.start (EmbeddedPostgres/builder))))
(def fresh-db!
(partial edb-utils/fresh-db! start-db!))
(comment
(def x
(start-db!))
(def ds
(fresh-db!))
;; Just checking to make sure we can connect to the DB and perform the
;; migrations
(jdbc/execute! ds ["select * from information_schema.tables"])
(jdbc/execute! ds ["select * from schema_migrations"])
(jdbc/execute! ds ["CREATE TABLE testing (id varchar)"])
(jdbc/execute! ds ["INSERT INTO testing VALUES ('hello')"])
(jdbc/execute! ds ["select * from testing"])
)