Skip to content

Commit

Permalink
Added describe-table to the database flavors to fix the field key nam…
Browse files Browse the repository at this point in the history
…e conflict between the two flavors.
  • Loading branch information
Matthew Courtney committed Jun 20, 2010
1 parent c17948d commit 6e72300
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
12 changes: 12 additions & 0 deletions conjure_core/src/conjure/core/db/flavors/h2.clj
Expand Up @@ -241,6 +241,17 @@ create-table method.
(sql/with-connection db-spec
(sql/drop-table (table-name table)))))

(defn-
update-column-desc [column-description]
(let [field (:column_name column-description)]
(assoc (dissoc column-description :column_name) :field field)))

(defn
describe-table [db-spec table]
(do
(logging/debug (str "Describe table: " table))
(map update-column-desc (execute-query db-spec [(str "SHOW COLUMNS FROM " (table-name table))]))))

(defn
#^{:doc "Deletes rows from the table with the given name."}
delete [db-spec table where]
Expand Down Expand Up @@ -275,6 +286,7 @@ create-table method.
:sql-find sql-find
:create-table create-table
:drop-table drop-table
:describe-table describe-table
:delete delete
:integer integer
:id id
Expand Down
7 changes: 7 additions & 0 deletions conjure_core/src/conjure/core/db/flavors/mysql.clj
Expand Up @@ -229,6 +229,12 @@ create-table method.
(sql/with-connection db-spec
(sql/drop-table (table-name table)))))

(defn
describe-table [db-spec table]
(do
(logging/debug (str "Describe table: " table))
(execute-query db-spec [(str "SHOW COLUMNS FROM " (table-name table))])))

(defn
#^{:doc "Deletes rows from the table with the given name."}
delete [db-spec table where]
Expand Down Expand Up @@ -263,6 +269,7 @@ create-table method.
:sql-find sql-find
:create-table create-table
:drop-table drop-table
:describe-table describe-table
:delete delete
:integer integer
:id id
Expand Down
34 changes: 18 additions & 16 deletions conjure_core/src/conjure/core/model/database.clj
Expand Up @@ -37,21 +37,23 @@ database flavor function with the current db spec and any arguments"}
(let [spec-name (string-utils/str-keyword type-key)]
`(defn ~(symbol spec-name)
([& args#] (call-db-fn ~type-key db args#)))))

(def-db-fn :table-exists?)

(def-db-fn :sql-find)
(def-db-fn :create-table)

(def-db-fn :delete)

(def-db-fn :describe-table)

(def-db-fn :drop-table)

(def-db-fn :insert-into)

(def-db-fn :update)
(def-db-fn :sql-find)

(def-db-fn :create-table)
(def-db-fn :table-exists?)

(def-db-fn :drop-table)
(def-db-fn :update)

(def-db-fn :delete)

(defmacro
#^{:doc "Given the type-key of a function in the database flavor, define a function named type-key which calls the
database flavor function passing any arguments."}
Expand All @@ -60,21 +62,21 @@ database flavor function passing any arguments."}
`(defn ~(symbol spec-name)
([& args#] (call-db-fn ~type-key args#)))))

(def-column-spec :integer)

(def-column-spec :string)
(def-column-spec :belongs-to)

(def-column-spec :text)
(def-column-spec :date)

(def-column-spec :belongs-to)
(def-column-spec :date-time)

(def-column-spec :id)

(def-column-spec :date)
(def-column-spec :integer)

(def-column-spec :time-type)
(def-column-spec :string)

(def-column-spec :date-time)
(def-column-spec :text)

(def-column-spec :time-type)

(defmacro
#^{:doc "Given the type-key of a function in the database flavor, define a function named type-key which calls the
Expand Down
3 changes: 2 additions & 1 deletion conjure_core/src/helpers/template_helper.clj
@@ -1,5 +1,6 @@
(ns helpers.template-helper
(:require [clj-record.core :as clj-record-core]
[conjure.core.model.database :as database]
[conjure.core.model.util :as model-util]
[conjure.core.server.request :as request]
[conjure.core.util.string-utils :as string-utils]
Expand All @@ -9,7 +10,7 @@
#^{ :doc "Returns the metadata for the given model." }
table-metadata [model-name]
(model-util/load-model model-name)
(clj-record-core/find-by-sql model-name [(str "SHOW COLUMNS FROM " (clj-record-core/table-name model-name))]))
(database/describe-table (clj-record-core/table-name model-name)))

(defn
#^{ :doc "Returns the result of a find records call on the given model with the given attributes" }
Expand Down
1 change: 0 additions & 1 deletion conjure_core/src/views/templates/list_records.clj
Expand Up @@ -9,7 +9,6 @@
(defn
#^{ :doc "Creates the header text from the given table-column." }
header-name [table-column]
(logging/debug (str "table-column: " table-column))
[:th (conjure-str-utils/human-title-case
(conjure-str-utils/strip-ending
(.toLowerCase (:field table-column))
Expand Down

0 comments on commit 6e72300

Please sign in to comment.