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