https://github.com/bts/jdbca
An asynchronous Clojure interface to JDBC
https://github.com/bts/jdbca
Last synced: 12 months ago
JSON representation
An asynchronous Clojure interface to JDBC
- Host: GitHub
- URL: https://github.com/bts/jdbca
- Owner: bts
- Created: 2015-03-08T17:21:37.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-03-14T15:50:27.000Z (about 11 years ago)
- Last Synced: 2025-01-11T17:48:16.772Z (over 1 year ago)
- Language: Clojure
- Homepage:
- Size: 334 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jdbca
An **in-progress** asynchronous [manifold](https://github.com/ztellman/manifold) interface to the synchronous [java.jdbc](https://github.com/clojure/java.jdbc) using a [dirigiste](https://github.com/ztellman/dirigiste) [thread pool](http://ideolalia.com/dirigiste/io/aleph/dirigiste/Executor.html). This library is [not yet ready](#caveats) for serious use.
```clojure
[jdbca "0.1.0-SNAPSHOT"]
```
## Usage
```clojure
(require '[jdbca :as j])
(require '[manifold.stream :as s])
;; db would be a connection pool in production code
(def db {:subprotocol "postgresql"
:subname "//localhost:5432/bts"
:user "bts"
:password ""})
(-> (j/query db ["select *, pg_sleep(1) from dogs where name = ?" "abe"])
(d/chain
(partial s/map :name)
s/take!)
(d/catch
(fn [e] "caught: " e)))
;=> << … >>
*1
;=> << "abe" >>
```
## Caveats
This project currently only contains the JDBC functionality I need in another project. Contributions are welcome.
Next on the list is transaction support. I'm currently considering a faux-monadic interface that's a blend of [`let-flow`](https://github.com/ztellman/manifold/blob/master/docs/deferred.md#let-flow) and postgres.async's [`dosql`](https://github.com/alaisi/postgres.async#composition), where each of the bindings will be made sequentially, and any failure will result in the entire form realizing an error-deferred:
```clojure
(j/do [tx (j/begin {:isolation :serializable})
rs1 (j/execute! tx ["insert into dogs (name) values (?)" "new dog"])
rs2 (j/execute! tx ["insert into cats (name) values (?)" "new cat"])
_ (j/commit!)]
(concat rs1 rs1))
```
To simplify transaction semantics, I think the current `j/query` function should probably be changed to just return a deferred yielding a clojure sequence instead of a manifold stream.
## License
Copyright © 2015 Brian Schroeder
Distributed under the MIT License.