Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code generation tool for SQL schema to Korma entities

Tags:

sql

clojure

korma

Is there a tool to convert a SQL schema to Korma entities?

like image 730
Timo Westkämper Avatar asked Jul 11 '12 14:07

Timo Westkämper


2 Answers

Not yet, but you could query you DBMS' Data Dictionary to get you started.

For instance, on MySQL you could start with:

select concat('(defentity ', t.table_name ,')') as defentity
  from information_schema.tables t
  where table_schema = 'mySchema';
like image 104
Henrique Ordine Avatar answered Sep 28 '22 07:09

Henrique Ordine


This works for me, took some thought to implement. I was a bit blown back that Korma does not have this feature! (note: I ran this against MSSQL)

(defentity INFORMATION_SCHEMA.tables)
(def tables (map #(get % :TABLE_NAME) 
              (select 'INFORMATION_SCHEMA.tables (fields :TABLE_NAME) 
                      (where {:TABLE_TYPE "BASE TABLE"})))) ;notice the quote

(prn tables)
;(map #(def %) tables) ;additional concept
(map #(defentity %) tables) ;not sure this is required anymore

(select (first tables))
like image 43
scape Avatar answered Sep 28 '22 06:09

scape