Clarify position on default options

I.e., write your own wrapper if you want to globally override options.
This commit is contained in:
Sean Corfield 2019-07-24 22:49:24 -07:00
parent 060ab6ba73
commit 5424353f2d
2 changed files with 5 additions and 1 deletions

View file

@ -20,6 +20,8 @@ Because `clojure.java.jdbc` focuses on a hash map for the `db-spec` that is pass
In [All The Options](doc/all-the-options.md), the appropriate options are shown for each function, as well as which options _will_ get passed down the call chain, e.g., if a function can open a connection, it will accept options for `get-connection`; if a function can build a result set, it will accept `:builder-fn`. However, `get-datasource`, `get-connection`, and `prepare` cannot propagate options any further because they produce Java objects as their results -- in particular, `prepare` can't accept `:builder-fn` because it doesn't build result sets: only `plan`, `execute-one!`, and `execute!` can use `:builder-fn`. In [All The Options](doc/all-the-options.md), the appropriate options are shown for each function, as well as which options _will_ get passed down the call chain, e.g., if a function can open a connection, it will accept options for `get-connection`; if a function can build a result set, it will accept `:builder-fn`. However, `get-datasource`, `get-connection`, and `prepare` cannot propagate options any further because they produce Java objects as their results -- in particular, `prepare` can't accept `:builder-fn` because it doesn't build result sets: only `plan`, `execute-one!`, and `execute!` can use `:builder-fn`.
In particular, this means that you can't globally override the default options (as you could with `clojure.java.jdbc` by adding your preferred defaults to the db-spec itself). If the default options do not suit your usage and you really don't want to override them in every call, it is recommended that you provide a wrapper namespace that implements the subset of the dozen API functions (from `next.jdbc` and `next.jdbc.sql` that you want to use), overriding their `opts` argument with your defaults.
## Primary API ## Primary API
`next.jdbc` has a deliberately narrow primary API that has (almost) no direct overlap with `clojure.java.jdbc`: `next.jdbc` has a deliberately narrow primary API that has (almost) no direct overlap with `clojure.java.jdbc`:

View file

@ -5,7 +5,9 @@
providing some syntactic sugar over `execute!`/`execute-one!`. providing some syntactic sugar over `execute!`/`execute-one!`.
This is intended to provide a minimal level of parity with This is intended to provide a minimal level of parity with
`clojure.java.jdbc` (`insert!`, `update!`, `delete!`, etc). `clojure.java.jdbc` (`insert!`, `insert-multi!`, `query`, `find-by-keys`,
`get-by-id`, `update!`, and `delete!`).
For anything more complex, use a library like HoneySQL For anything more complex, use a library like HoneySQL
https://github.com/jkk/honeysql to generate SQL + parameters. https://github.com/jkk/honeysql to generate SQL + parameters.