mysql golang 根据表名转为struct,部分常用类型匹配,带注释。 - Go语言中文社区

mysql golang 根据表名转为struct,部分常用类型匹配,带注释。


-- mysql golang 根据表名转为struct,部分常用类型匹配,带注释。
select concat(
    UPPER(SUBSTRING(COLUMN_NAME,1,1)),
    SUBSTRING(COLUMN_NAME,2,length(COLUMN_NAME)),
    (case DATA_TYPE
        when 'varchar' then ' string '
        when 'int' then ' int '
        when 'double' then ' float32 '
        when 'float' then ' float64 '
        when 'datetime' then ' string '
        end),
        '`json:"',
        COLUMN_NAME,
        '"`',
        '// ',
        COLUMN_COMMENT
) as golang_variable
from (
    select 
        ORDINAL_POSITION,
    COLUMN_NAME,
    DATA_TYPE,
    COLUMN_COMMENT from information_schema.COLUMNS 
    where table_name = 'teacher' -- 填写所需要的表名
) a order by ORDINAL_POSITION
-- 支持mysql8.0+

1706925-20190605142440907-1290104404.png

转载于:https://www.cnblogs.com/alixiaoyao/p/10974560.html

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_34107739/article/details/94608824
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-06 22:25:27
  • 阅读 ( 1466 )
  • 分类:数据库

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢