Code generation tool for SQL schema to Korma entities
Asked Answered
U

2

10

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

Ultraconservative answered 11/7, 2012 at 14:20 Comment(0)
M
2

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';
Mann answered 16/8, 2012 at 9:44 Comment(1)
Interesting, but using JDBC metadata would be a portable alternative.Congeneric
A
2

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))
Amish answered 1/8, 2013 at 20:41 Comment(2)
Looks nice, but you can use :TABLE_NAME as the first argument of the first map callCongeneric
like #{:TABLE_NAME} ? I should try that in a filter maybeAmish

© 2022 - 2024 — McMap. All rights reserved.