Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 7ec8e84405c251e760d8f716c016edd1ded84188 @kumarshantanu committed Jun 24, 2012
@@ -0,0 +1,11 @@
+
+## 0.7 / 2012-June-??
+
+* Move to Github
+* Move to Leiningen 2 for builds
+* Move to Eclipse license
+* Refactor API
+ * Drop properties file support
+ * Drop per-database API functions
+ * Adopt generic API based on keywords
+
@@ -0,0 +1,130 @@
+# clj-dbcp
+
+Clojure wrapper for Apache DBCP to create JDBC connections pools.
+
+This code is rewritten from scratch to clean up the older versions residing
+here: https://bitbucket.org/kumarshantanu/clj-dbcp
+
+The supported databases are:
+* Supported and tested
+ * Apache Derby, Axion, HSQLDB, H2, Mckoi, SQLite
+* Supported but not tested
+ * Regular ODBC DSN, Lite ODBC DSN (eg. MS-Excel workbooks)
+ * CUBRID, Firebird, MySQL, MonetDB, PostgreSQL
+ * IBM DB2, jTDS (SQL Server, Sybase), Oracle, SapDB, SQLServer, Sybase
+
+
+## Usage
+
+_This library is not on Clojars yet._
+
+Include dependencies as `[clj-dbcp "0.7.0-SNAPSHOT"]`.
+
+The recommended way to create a datasource is to call the
+`clj-dbcp.core/make-datasource` function, for example:
+
+```clojure
+(make-datasource {:adapter :mysql :host 'localhost :database 'empdb})
+```
+
+Sections below describe which of the keys are applicable to various databases:
+
+### Embedded databases
+
+| Database |`:adapter` | `:target` | Required keys | Optional keys |
+|----------|------------|------------|-------------------------|---------------|
+| Axion | `:axiondb` | `:memory` | `:database` | |
+| | | `:filesys` | `:database` `:db-path` | |
+| Derby | `:derby` | `:memory` | `:database` | |
+| | | `:filesys` | `:database` | |
+| | |`:classpath`| `:database` | |
+| | | `:jar` | `:jar-path` `:database` | |
+| | | `:network` | `:host` `:database` | `:port` |
+| H2 | `:h2` | `:memory` | `:database` | |
+| | | `:filesys` | `:database` | |
+| | | `:network` | `:host` `:database` | `:port` |
+| HSQLDB | `:hsqldb` | `:memory` | `:database` | |
+| | | `:filesys` | `:database` | |
+| | | `:network` | `:host` `database` | `:port` |
+| Mckoi | `:mckoi` | `:filesys` | `:database` | |
+| SQLite | `:sqlite` | `:memory` | | |
+| | | `:filesys` | `:database` | |
+
+
+### Example
+
+A typical CRUD example using Derby database is below:
+
+```clojure
+(ns example.app
+ (:require [clj-dbcp.core :as dbcp]
+ [clojure.java.jdbc :as sql]))
+
+(def db-derby ;; an in-memory database instance
+ {:datasource
+ (dbcp/make-datasource
+ {:adapter :derby :target :memory :database :empdb})})
+
+(defn crud
+ []
+ (let [table :emp
+ orig-record {:id 1 :name "Bashir" :age 40}
+ updt-record {:id 1 :name "Shabir" :age 50}
+ drop-table #(sql/do-commands "DROP TABLE emp")
+ retrieve-fn #(sql/with-query-results rows
+ ["SELECT * FROM emp WHERE id=?" 1]
+ (first rows))]
+ (sql/with-connection db-derby
+ ;; drop table if pre-exists
+ (try (drop-table)
+ (catch Exception _)) ; ignore exception
+ ;; create table
+ (sql/do-commands
+ "CREATE TABLE emp (id INTEGER, name VARCHAR(50), age INTEGER)")
+ ;; insert
+ (sql/insert-values table (keys orig-record) (vals orig-record))
+ ;; retrieve
+ (println (retrieve-fn))
+ ;; update
+ (sql/update-values table ["id=?" 1] updt-record)
+ ;; drop table
+ (drop-table))))
+```
+
+
+## Development Notes
+
+You need Java 7 and Leiningen 2 to build this code. Testing JDBC-ODBC bridge
+driver requires that you use a Windows machine with ODBC DSNs configured.
+
+Starting up the swank server (if you are going to work using Emacs/Slime):
+
+```bash
+$ lein2 dev swank
+```
+
+Testing against the dev version:
+
+```bash
+$ lein2 dev test
+```
+
+Testing across several versions of Clojure:
+
+```bash
+$ lein2 all test
+```
+
+
+## Getting in touch
+
+On GMail: [kumar.shantanu(at)gmail.com](mailto:kumar.shantanu@gmail.com)
+
+On Twitter: [@kumarshantanu](https://twitter.com/kumarshantanu)
+
+
+## License
+
+Copyright © 2012 Shantanu Kumar
+
+Distributed under the Eclipse Public License, the same as Clojure.
@@ -0,0 +1,4 @@
+#!/usr/bin/env sh
+
+rm -rf default* derby* log*
+
Oops, something went wrong.

0 comments on commit 7ec8e84

Please sign in to comment.