I am trying to query a postgres database that I have set up locally on my machine.
I have created a file
(ns website.db
(:require [clojure.java.jdbc :as jdbc]))
(def database
{:classname "com.postgres.jdbc.Driver"
:subprotocol "postgres"
:subname "mydb" ; In the guide this was //127.0.0.1:3306/mydb. Is the first part my computer IP address?
:user "admin"
:password "secret"})
If I then try to query the database using (in the REPL)
(jdbc/query database ["SELECT * FROM table"])
I get the error ConnectException Connection refused java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java:-2)
Note I expect the database to be empty as I haven't entered any information into the database
What mistake have I made when defining my database?
To insert a user is this correct:
(defn register-user! [db name]
(jdbc/insert! db :user {:name name}))
(def pg-db {:dbtype "postgresql" :dbname "mypgdatabase" :host "mydb.server.com" :user "myuser" :password "secret" :ssl true :sslfactory "org.postgresql.ssl.NonValidatingFactory"})