summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md30
-rw-r--r--src/clojure_sql/core.clj17
2 files changed, 36 insertions, 11 deletions
diff --git a/README.md b/README.md
index cd688cc..e9ebb86 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,33 @@
# clojure-sql
-A DSL for [Clojure][1] to compose queries using the constructs of [Relational
-Algebra][2]. The RA constructs are then compiled into an SQL query to be run on
-a DBMS.
+A DSL for [Clojure][1] to compose queries using the constructs of
+[Relational Algebra][2]. The RA constructs are then compiled into an
+SQL query to be run on a DBMS. `clojure-sql` doesn't connect to a
+database itself, but rather can be configured to perform an action
+when a query is dereferenced.
-`clojure-sql` provides some utility functions beyond strict RA to allow for
-data to be inserted, updated and deleted.
+`clojure-sql` provides some utility functions beyond strict RA to
+allow for data to be inserted, updated and deleted.
`clojure-sql` provides no mechanism to create database schemas.
[1]: http://clojure.org/
[2]: http://en.wikipedia.org/wiki/Relational_Algebra
+## Database support
+
+`clojure-sql` aims to have an extensible compiler. Compilation of
+queries is performed by multimethods which dispatch on an arbitrary
+(and otherwise unused) `db` parameter. This allows the compilation of
+queries to be entirely special-cased per database. By default
+`clojure-sql` will produce standard SQL.
+
## Usage
(require '[clojure-sql.core :as s])
(-> (s/table :users)
- (s/project [:id :username])
- deref)
+ (s/project [:id :username]))
; => ["SELECT \"users\".\"id\", \"users\".\"username\" FROM \"users\""]
(-> (s/table {:users :u})
@@ -28,9 +37,12 @@ data to be inserted, updated and deleted.
(s/project {:id :pid, :fname :first})
(s/select '(= :first "Henry")))
'(= :uid :pid))
- (s/project [:username])
- deref)
+ (s/project [:username]))
; => ["SELECT \"u\".\"username\" FROM \"users\" AS \"u\" JOIN \"people\" AS \"p\" ON (\"u\".\"id\" = \"p\".\"id\") WHERE (\"p\".\"fname\" = ?)" "Henry")]
+
+ (s/use-jdbc!)
+ ; => nil
+
## License
diff --git a/src/clojure_sql/core.clj b/src/clojure_sql/core.clj
index 5d871c7..ae0eb75 100644
--- a/src/clojure_sql/core.clj
+++ b/src/clojure_sql/core.clj
@@ -8,11 +8,11 @@
(declare compile-query)
-(def ^:dynamic *database-type* nil)
+(def ^:private ^:dynamic *database-type* nil)
(defn set-database-type! [new-type]
(alter-var-root #'*database-type* (constantly new-type)))
-(def ^:dynamic *query-deref-behaviour* #(compile-query *database-type* %))
+(def ^:private ^:dynamic *query-deref-behaviour* #(compile-query *database-type* %))
(defn set-query-deref-behaviour! [f]
(alter-var-root #'*query-deref-behaviour* (constantly f)))
@@ -364,6 +364,19 @@
[(resolve-field table-name (:fields query) field) :asc])))))
+(defn insert! [query & records]
+ {:pre [(empty? (:joins query))]}
+ ;; some code here
+ )
+
+(defn update! [query & partial-records]
+ ;; some code here
+ )
+
+(defn delete! [query]
+ ;; some code here
+ )
+
(comment