summaryrefslogtreecommitdiff
path: root/README.md
blob: adfccdd00deb308cec0ba1b1b2f97b95d33b9650 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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.

`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

## Usage

    (require '[clojure-sql.core :as s])

    (-> (s/table :users)
        (s/project [:id :username])
        deref)
    ; => ["SELECT \"users\".\"id\", \"users\".\"username\" FROM \"users\"" ()]

    (-> (s/table {:users :u})
        (s/project [:id :username])
        (s/rename {:id :uid})
        (s/join (-> (s/table {:people :p})
                    (s/project {:id :pid, :fname :first})
                    (s/select '(= :first "Henry")))
                '(= :uid :pid))
        (s/project [:username])
        deref)
    ; => ["SELECT \"u\".\"username\" FROM \"users\" AS \"u\" JOIN \"people\" AS \"p\" ON (\"u\".\"id\" = \"p\".\"id\") WHERE (\"p\".\"fname\" = ?)" ("Henry"))]

## License

Copyright © 2013 FIXME

Distributed under the Eclipse Public License, the same as Clojure.