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+


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM