Skip to content

Commit

Permalink
Added basic support for indexes to the analyzer.
Browse files Browse the repository at this point in the history
  • Loading branch information
budu committed Apr 17, 2011
1 parent 3681526 commit 27f05c3
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/lobos/analyzer.clj
Expand Up @@ -16,9 +16,10 @@
lobos.utils)
(:import (java.sql DatabaseMetaData)
(lobos.schema Column
DataType
Expression
ForeignKeyConstraint
DataType
Index
Schema
Table
UniqueConstraint)))
Expand Down Expand Up @@ -105,6 +106,22 @@
(map (fn [[cname meta]] (analyze ForeignKeyConstraint cname meta))
(references-meta sname tname))))

(defmethod analyze [::standard Index]
[_ sname tname iname index-meta]
(let [pkeys (primary-keys sname tname)]
(Index.
(keyword iname)
tname
(vec (map #(-> % :column_name keyword)
index-meta))
(when (-> index-meta first :non_unique not)
(list :unique)))))

(defmethod analyze [::standard :indexes]
[_ sname tname]
(map (fn [[iname meta]] (analyze Index sname tname iname meta))
(indexes-meta sname tname)))

(defn analyze-data-type-args
"Returns a vector containing the data type arguments for the given
column meta data."
Expand Down Expand Up @@ -144,7 +161,9 @@
[(:cname c) c])
(columns-meta sname tname)))
(into {} (map #(vector (:cname %) %)
(analyze :constraints sname tname)))))
(analyze :constraints sname tname)))
(into {} (map #(vector (:iname %) %)
(analyze :indexes sname tname)))))

(defmethod analyze [::standard Schema]
[_ sname]
Expand Down

0 comments on commit 27f05c3

Please sign in to comment.