diff options
author | Carlo Zancanaro <carlo@clearboxsystems.com.au> | 2013-05-23 18:26:46 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@clearboxsystems.com.au> | 2013-05-23 18:26:46 +1000 |
commit | 5ccaca496f4babb4fef2d34e272b8772e077fa25 (patch) | |
tree | 39503109047318559e806372668bdfc092dbb1a6 /test/clojure_sql/core_test.clj | |
parent | 626ab0234ad2e578992d128ced35c2003902e90f (diff) |
Simplify the compiler, better subquery support
The compiler's been simplified a bit by breaking out the `writer` stuff into
its own namespace and by generally making the monadic stuff better. It's all
hidden behind a nice, simple, `clojure-sql.compiler/compile` function now. Call
that and you'll get back what you need. (Internally it's a writer monad which
is really modelled as a state monad with the only operation able to be
performed on the state being `tell`.)
Subqueries are now handled by the DSL in such a way as to not blow up
everything. Subqueries have no support for referencing values in the
superquery, though, so their utility is quite limited at present. Thinking
about how to do subqueries properly may be difficult.
Diffstat (limited to 'test/clojure_sql/core_test.clj')
-rw-r--r-- | test/clojure_sql/core_test.clj | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/test/clojure_sql/core_test.clj b/test/clojure_sql/core_test.clj index d6654cf..b5d65e7 100644 --- a/test/clojure_sql/core_test.clj +++ b/test/clojure_sql/core_test.clj @@ -3,9 +3,23 @@ (:require [clojure-sql.core :refer :all] [midje.sweet :refer :all])) -#_(fact - (compile-query nil (table :user)) +(fact + @(table :user) => ["SELECT * FROM \"user\""] + + @(-> (table :user) (select '(= :username "george"))) + => ["SELECT * FROM \"user\" WHERE (\"user\".\"username\" = ?)" "george"] - (compile-query nil (-> (table :user) (select '(= :username "george")))) - => ["SELECT * FROM \"user\" WHERE (\"user\".\"username\" = ?)" "george"]) + @(-> (table :user) (project {:username :u})) + => ["SELECT \"user\".\"username\" AS \"u\" FROM \"user\""] + + @(-> (table :user) (project {'(+ :username :password) :u})) + => ["SELECT (\"user\".\"username\" + \"user\".\"password\") AS \"u\" FROM \"user\""]) + +(into {} (-> (table :user) (project '{(+ :username :password) :u}))) + +(-> (table {(-> (table :users) + (project '[:username (+ 1 2 3)]) + (rename '{(+ 1 2 3) :x}) + (select `(exists ~(table :users)))) :u}) + println) |