Common API (Data Source Abstraction)
This PR introduces vast refactoring.
The main problem it addresses is that before, functions like `query` or `execute` accepted a Connection object only. And at some point, it has become inconvenient. For example, I have a Pool object, and every time I want to query something, first I have to fetch a connection and pass it into the function as follows:
```
(defn do-something [pool]
(pool/with-conn [conn pool]
(let [result (pg/query conn "select ...")])))
```
Some people can mix a connection with a pool, and pass a connection into the function, which will lead to an error.
This PR brings something that is common in next.jdbc: protocols. There is a single ISource protocol that gets extended by the following types:
- clojure map (clojure config)
- Connection
- Pool
- Config (java)
- URI String
Functions like `query` and `execute` accept not a connection any longer but any of these objects listed above. Also, now it's possible to create a connection or a pool not from a Clojure map, but from a URI as well.
I hope the new docs cover my intentions. Also, long Clojure->Java building functions are moved to separate namespaces to save lines.
cc @jgdavey so you're aware of these changes.
合并状态:未合并 关闭于 2025-01-29 1 条评论