Generated HugSQL queries now (all?) working.

This commit is contained in:
Simon Brooke 2018-06-14 21:26:23 +01:00
parent e67142db47
commit 8ee91b5372
5 changed files with 20 additions and 23 deletions

View file

@ -392,13 +392,10 @@
(defn queries (defn queries
"Generate all standard queries for this `entity` in this `application`; if "Generate all standard queries for this `entity` in this `application`; if
no entity is specified, generate all queris for the application." no entity is specified, generate all queries for the application."
([application entity] ([application entity]
(merge (merge
(if ;; TODO: queries that look through link tables
(link-table? entity)
(link-table-queries entity application)
{})
(insert-query entity) (insert-query entity)
(update-query entity) (update-query entity)
(delete-query entity) (delete-query entity)

View file

@ -47,12 +47,12 @@
(f/unparse (f/formatters :basic-date-time) (t/now))) (f/unparse (f/formatters :basic-date-time) (t/now)))
(list (list
:require :require
'[clojure.java.io :as io]
'[compojure.core :refer [defroutes GET POST]]
'[hugsql.core :as hugsql]
'[noir.response :as nresponse] '[noir.response :as nresponse]
'[noir.util.route :as route] '[noir.util.route :as route]
'[compojure.core :refer [defroutes GET POST]]
'[ring.util.http-response :as response] '[ring.util.http-response :as response]
'[clojure.java.io :as io]
'[hugsql.core :as hugsql]
(vector (symbol (str (safe-name (:name (:attrs application))) ".db.core")) :as 'db)))) (vector (symbol (str (safe-name (:name (:attrs application))) ".db.core")) :as 'db))))

View file

@ -44,12 +44,12 @@
(f/unparse (f/formatters :basic-date-time) (t/now))) (f/unparse (f/formatters :basic-date-time) (t/now)))
(list (list
:require :require
'[clojure.java.io :as io]
'[compojure.core :refer [defroutes GET POST]]
'[hugsql.core :as hugsql]
'[noir.response :as nresponse] '[noir.response :as nresponse]
'[noir.util.route :as route] '[noir.util.route :as route]
'[compojure.core :refer [defroutes GET POST]]
'[ring.util.http-response :as response] '[ring.util.http-response :as response]
'[clojure.java.io :as io]
'[hugsql.core :as hugsql]
(vector (symbol (str (:name (:attrs application)) ".layout")) :as 'l) (vector (symbol (str (:name (:attrs application)) ".layout")) :as 'l)
(vector (symbol (str (:name (:attrs application)) ".db.core")) :as 'db) (vector (symbol (str (:name (:attrs application)) ".db.core")) :as 'db)
(vector (symbol (str (:name (:attrs application)) ".routes.manual")) :as 'm)))) (vector (symbol (str (:name (:attrs application)) ".routes.manual")) :as 'm))))

View file

@ -480,7 +480,7 @@
(list-page-control true)]}) (list-page-control true)]})
(defn- list-to-template (defn list-to-template
"Generate a template as specified by this `list` element for this `entity`, "Generate a template as specified by this `list` element for this `entity`,
taken from this `application`. If `list` is nill, generate a default list taken from this `application`. If `list` is nill, generate a default list
template for the entity." template for the entity."
@ -502,9 +502,9 @@
`entity` in this `application`" `entity` in this `application`"
[entity application] [entity application]
(let (let
[forms (children entity #(= (:tag %) :form)) [forms (children-with-tag entity :form)
pages (children entity #(= (:tag %) :page)) pages (children-with-tag entity :page)
lists (children entity #(= (:tag %) :list))] lists (children-with-tag entity :list)]
(if (if
(and (and
(= (:tag entity) :entity) ;; it seems to be an ADL entity (= (:tag entity) :entity) ;; it seems to be an ADL entity

View file

@ -281,14 +281,6 @@
(safe-name string)))))) (safe-name string))))))
(defn link-table?
"Return true if this `entity` represents a link table."
[entity]
(let [properties (children entity #(= (:tag %) :property))
links (filter #(-> % :attrs :entity) properties)]
(= (count properties) (count links))))
(defn read-adl [url] (defn read-adl [url]
(let [adl (x/parse url) (let [adl (x/parse url)
valid? (valid-adl? adl)] valid? (valid-adl? adl)]
@ -371,6 +363,14 @@
`(filter insertable? (key-properties entity))) `(filter insertable? (key-properties entity)))
(defn link-table?
"Return true if this `entity` represents a link table."
[entity]
(let [properties (all-properties entity)
links (filter #(-> % :attrs :entity) properties)]
(= (count properties) (count links))))
(defn key-names [entity] (defn key-names [entity]
(remove (remove
nil? nil?