title: Clojure: From Prismatic Schema nested data structure to SQL Tables
body: <p>I would like to convert a Prismatic Schema nested specs to flat SQL tables creation where when adding lines, schema gets validated.  </p>
  
  <pre><code>(defn max-length [l] (s/pred (fn [x] (&lt;= (count x) l))))
  (defn min-length [l] (s/pred (fn [x] (&gt;= (count x) l))))
  (defn length     [l] (s/pred (fn [x] (= (count x) l))))
  (defn matches    [r] (s/pred (fn [s] (re-matches r s))))
  
  (defn linked-to-many [&amp; keys] ???)
  (defn schema-&gt;tables [coll]   ???)
  (defn add-line       [t coll] ???)
  
  (def schema 
    {:ideas {:id s/Uuid                               ; not sure about this type
             :title (s/both s/String (max-length 50))
             :tags (linked-to-many :tags :id)         ; a list of tag ids
             :votes (linked-to-many :users :id)       ; a list of user ids
             (s/optional :desc) (s/both s/String (max-length 300))} 
     :users {:id s/Uuid
             :f-name (s/both s/String (min-length 2))
             :l-name (s/both s/String (min-length 2))
             :zip (s/both s/Int (length 5))
             :email (s/both (min-length 5) (matches #".*@.*"))
             (s/optional :no-spam) s/Bool}
     :tags {:id 
            :name (s/both s/String (max-length 15))
            :related (linked-to-many :tags :id) }     ; similar tag ids
  
  (schema-&gt;tables schema)
  ;=&gt; sql tables...
  
  (add-line :tags {:name "Too long tag name which will trigger prismatic error"
                   :related [1 23 8]}) 
  ;=&gt; prismatic validation error
  </code></pre>
  
  <p>I suppose it should create 6 SQL tables adding :votes, :tags-ideas and :tags-tags tables...</p>
  
  <p>How can I achieve this? 
  Are there any libraries that can help me with this project? 
  (Maybe I could use something like <a href="https://github.com/friemen/aggregate" rel="nofollow">aggregate</a>?)</p>