I wrote postgres support for clojureql. It's my first shot, but the
demo runs through from start to finish.

Of course you need postgres jdbc drivers, e.g.
http://jdbc.postgresql.org/download/postgresql-8.4-701.jdbc4.jar

***** dk/bestinclass/clojureql/backend/postgresql.clj:

(clojure.core/ns dk.bestinclass.clojureql.backend.postgresql
  (:require
     [dk.bestinclass.clojureql :as cql]
     [dk.bestinclass.clojureql.util :as util]))

(defmethod cql/compile-sql
  [::cql/CreateTable org.postgresql.PGConnection]
  [stmt db]
  (let [{:keys [table
                columns
                options]}   stmt]
    (apply str
           (list "CREATE TABLE " table
                 " ("
                 (util/str-cat ", "
                               (map #(str (first %) " " (if (= (first
%) (:auto-inc options))
 
"SERIAL" (second %))
                                          (when (= (first %) (:not-
null options))
                                            " NOT NULL "))
                                    columns))
                 (when-not (nil? (:primary-key options))
                   (format ", PRIMARY KEY (\"%s\")" (:primary-key
options)))
                 ") "))))

(prefer-method cql/compile-sql
               [::cql/CreateTable org.postgresql.PGConnection]
               [::cql/CreateTable ::cql/Generic])



***** dk/bestinclass/clojureql/demos/postgresql.clj:

(ns dk.bestinclass.clojureql.demos.postgresql
  (:gen-class)
  (:require
     [dk.bestinclass.clojureql :as sql]
     [dk.bestinclass.clojureql.backend.postgresql :as postgresql]))

; Adapt the following connection-info to your local database.
(def *conn-info*
     (sql/make-connection-info "postgresql"         ; Type
                               "//localhost/cql"    ; Adress and db
(cql)
                               "cql"                ; Username
                               "cql"))              ; Password

(sql/load-driver "org.postgresql.Driver")

(load "common")

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to