Skip to content

Commit

Permalink
Added default compiler support for check constraints.
Browse files Browse the repository at this point in the history
  • Loading branch information
budu committed Jan 9, 2011
1 parent 272aadd commit 4a37bb3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/lobos/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
(ns lobos.compiler
"The compiler multimethod definition, an default implementation and
some helpers functions."
(:refer-clojure :exclude [compile])
(:refer-clojure :exclude [compile replace])
(:require (lobos [ast :as ast]))
(:use lobos.utils)
(:use (clojure [string :only [replace]])
lobos.utils)
(:import (java.lang UnsupportedOperationException)
(lobos.ast AutoIncClause
CheckConstraintDefinition
ColumnDefinition
CreateTableStatement
CreateSchemaStatement
Expand Down Expand Up @@ -143,6 +145,18 @@
(when (contains? triggered-actions :on-update)
(str "ON UPDATE " (as-sql-keyword (:on-update triggered-actions)))))))

(defmethod compile [::standard CheckConstraintDefinition]
[definition]
(let [{:keys [db-spec cname condition identifiers]} definition
identifiers-re (re-pattern (apply join \| identifiers))]
(join \space
"CONSTRAINT"
(as-identifier db-spec cname)
"CHECK"
(replace condition
identifiers-re
#(as-identifier db-spec %)))))

;;; Statements

(defmethod compile [::standard CreateSchemaStatement]
Expand Down

0 comments on commit 4a37bb3

Please sign in to comment.