-
-
Save shukebeta/b315c940f63277fa982e6c93c0f97040 to your computer and use it in GitHub Desktop.
Outputs a POCO for a given MySql table. Based on http://stackoverflow.com/a/13918084/21865 with mild formatting changes and additional types added.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select '%TABLE_NAME%' | |
into @table; | |
select '%DB_NAME%' | |
into @schema; | |
select concat(' public class ', @table) | |
union | |
select ' {' | |
union | |
select concat(' public ', tps.dest, ' ', column_name, ' { get; set; }') | |
from information_schema.columns c | |
join ( | |
select 'char' as orign, 'string' as dest | |
union all | |
select 'varchar', 'string' | |
union all | |
select 'timestamp', 'DateTime' | |
union all | |
select 'datetime', 'DateTime' | |
union all | |
select 'date', 'DateTime' | |
union all | |
select 'text', 'string' | |
union all | |
select 'binary', 'byte[]' | |
union all | |
select 'int', 'int' | |
union all | |
select 'decimal', 'decimal' | |
union all | |
select 'float', 'float' | |
union all | |
select 'tinyint', 'bool' | |
) tps on c.data_type like tps.orign | |
where table_schema = @schema | |
and table_name = @table | |
union | |
select ' }'; |
Author
shukebeta
commented
Aug 11, 2020
•
- Save this snippet into a file named 'Model.tmpl.sql'
- Save the following code into a file named 'addModel.sh'
- change a few variable definitions mentioned in the comment in the shell script
- enjoy!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment