stch-library / sql

A DSL in Clojure for SQL query, DML, and DDL. Supports a majority of MySQL's statements.
Eclipse Public License 1.0
41 stars 7 forks source link

Calling the 'call' function results in an exception #5

Open felixflores opened 9 years ago

felixflores commented 9 years ago
(ns my.stuff
  (:require [stch.sql.format :as sql]
            [clojure.java.jdbc :refer [execute!]]
            [stch.sql.types :refer [call]]
            [stch.sql.ddl :refer [create timestamp integer primary-key serial table default]]))

(def db {:classname "org.postgresql.Driver"
         :subprotocol "postgresql"
         :user "stuff"
         :password ""
         :subname "//localhost:5432/mydb"})

(defn db-execute!
  [statement]
  (execute! db statement))

(db-execute! [(-> (table :schema_versions)
                  (serial :id :not-null)
                  (primary-key :id)
                  (integer :version)
                  (timestamp :created_at (default (call :now)))
                  (create))])

;=> CompilerException java.lang.IllegalArgumentException: No implementation of method: :to-sql of protocol: #'stch.sql.ddl/ToSQL found for class: stch.sql.types.SqlCall, compiling:(config/migrate_config.clj:1:31) 
dubiousdavid commented 9 years ago

I'm happy to accept a PR for this. You will need to add extend the ToSQL protocol (https://github.com/stch-library/sql/blob/master/src/stch/sql/ddl.clj#L29) for the SqlCall type (https://github.com/stch-library/sql/blob/master/src/stch/sql/types.clj#L4).