Thu, 25 Feb 2010

A preview of ClojureQL

As you might already know, I'm rewriting ClojureQL. This takes a lot of time at the moment, so I don't find much time to blog. But to not stall the blog completely and to shorten the time a little until the first version of CQL is released I decided to provide a little example on the look'n'feel of the new frontend. So here we go…

Clojure
user=> (ns cql.test
         (:refer-clojure :exclude (= not= <= >= < > nil? count
                                     min max count first last and or not))
         (:use clojureql.query)
         (:require clojureql.sql))
nil
cql.test=> (def c (proxy [java.sql.Connection] []))
#'cql.test/c
cql.test=> (-> (from :table [:a :b :c])
         (compile-query c))
{:sql "SELECT a, c, b FROM table", :env []}
cql.test=> (-> (from :table [:a :b :c])
         (where (and (<= :a 5) (= :table.x "Hello, World!")))
         (compile-query c))
{:sql "SELECT a, c, b FROM table WHERE (a <= ?) AND (table.x = ?)",
 :env [5 "Hello, World!"]}
cql.test=> (-> (from :table [:a :b :c])
         (order-by :ascending :a)
         (where (and (<= :a 5) (= :table.x "Hello, World!")))
         (compile-query c))
{:sql "SELECT a, c, b FROM table WHERE (a <= ?) AND (table.x = ?) ORDER BY a ASC",
 :env [5 "Hello, World!"]}
cql.test=> (-> (from :table [:a :b :c])
         (order-by :ascending :a)
         (group-by {:c sum} :a :b)
         (where (and (<= :a 5) (= :table.x "Hello, World!")))
         (compile-query c))
{:sql "SELECT a, b, sum(c) FROM table WHERE (a <= ?) AND (table.x = ?) GROUP BY a, b ORDER BY a ASC",
 :env [5 "Hello, World!"]}
cql.test=> (-> (from :table [:a :b :c])
         (order-by :ascending :a)
         (group-by {:c sum} :a :b)
         (having (> (sum :c) 100))
         (where (and (<= :a 5) (= :table.x "Hello, World!")))
         (compile-query c))
{:sql "SELECT a, b, sum(c) FROM table WHERE (a <= ?) AND (table.x = ?) GROUP BY a, b HAVING sum(c) > ? ORDER BY a ASC",
 :env [5 "Hello, World!" 100]}
cql.test=>

But please don't hold your breath. There is already a lot done. But there is also still a lot to do. More information can be found in the repo and the tracker. General information can be found on the gitorious wiki. Nicolas Buduroi is also working on DDL rework.

Stay tuned for more changes. :)

Published by Meikel Brandmeyer on 25 Feb 2010 23:31

Bookmark and Share