Fork me on GitHub
#sql
<
2017-03-15
>
not-raspberry19:03:34

I use Luminus with Postgres. By default Luminus extends some protocols from clojure.java.jdbc, as well as adds set-parameter to some Clojure/Java types. How to extend the same protocols/types with pgjdbc-ng?

not-raspberry19:03:30

I understand that clojure.java.jdbc is just a wrapped for the stock jdbc, and won't work with pgjdbc-ng.

not-raspberry19:03:53

The easiest thing may be to continue using the default interface and use pgjdbc-ng only where I actually need it (for LISTEN).

donaldball19:03:22

It’s not immediately obvious why pgjdbc-ng couldn’t work with clojure.java.jdbc, at least for the common jdbc features?

donaldball19:03:57

It permits connections to be opened against javax.sql.DataSource impls

not-raspberry20:03:26

I was thinking that maybe clojure.java.jdbc hardcodes the dependency on Java's jdbc.

hiredman20:03:55

pgjdbc-ng is a jdbc driver

seancorfield20:03:02

java.jdbc has actually been tested with pgjdbc-ng

seancorfield20:03:32

I may need to make a new release with that update in… let me just check...

seancorfield20:03:59

@not-raspberry java.jdbc uses whatever JDBC driver you add as a dependency and whatever driver class you specify. Some have shortcuts (e.g., mysql, mssql, postgres — default PostgreSQL drive). That change added pgsql as a shortcut for the Impossibl pgjdbc-ng driver.

seancorfield20:03:04

These are the drivers java.jdbc knows about out of the box:

(def ^{:private true :doc "Map of classnames to subprotocols"} classnames
  {"derby"          "org.apache.derby.jdbc.EmbeddedDriver"
   "h2"             "org.h2.Driver"
   "hsqldb"         "org.hsqldb.jdbcDriver"
   "jtds:sqlserver" "net.sourceforge.jtds.jdbc.Driver"
   "mysql"          "com.mysql.jdbc.Driver"
   "oracle:oci"     "oracle.jdbc.OracleDriver"
   "oracle:thin"    "oracle.jdbc.OracleDriver"
   "postgresql"     "org.postgresql.Driver"
   "pgsql"          "com.impossibl.postgres.jdbc.PGDriver"
   "sqlite"         "org.sqlite.JDBC"
   "sqlserver"      "com.microsoft.sqlserver.jdbc.SQLServerDriver"})
and it has the following shortcut aliases too
(def ^{:private true :doc "Map of schemes to subprotocols"} subprotocols
  {"hsql"     "hsqldb"
   "jtds"     "jtds:sqlserver"
   "mssql"    "sqlserver"
   "oracle"   "oracle:thin"
   "postgres" "postgresql"})
Anything else you need to specify long-hand like this
DriverManager (alternative / legacy style):
    :subprotocol (required) a String, the jdbc subprotocol
    :subname     (required) a String, the jdbc subname
    :classname   (optional) a String, the jdbc driver class name
    (others)     (optional) passed to the driver as properties.

seancorfield20:03:31

The “built-in” names can be used with this shorthand:

DriverManager (preferred):
    :dbtype      (required) a String, the type of the database (the jdbc subprotocol)
    :dbname      (required) a String, the name of the database
    :host        (optional) a String, the host name/IP of the database
                            (defaults to 127.0.0.1)
    :port        (optional) a Long, the port of the database
                            (defaults to 3306 for mysql, 1433 for mssql/jtds, else nil)
    (others)     (optional) passed to the driver as properties.

seancorfield20:03:49

LMK if anything about that isn’t clear.

not-raspberry20:03:36

Thanks, everyone, I'll try tomorrow.

seancorfield20:03:21

Feel free to ping me if you have any issues with java.jdbc!