2 Star 1 Fork 1

mosache / YFrame

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dao.go 983 Bytes
一键复制 编辑 原始数据 按行查看 历史
ヤ沒脩袮兲︶ 提交于 2023-03-15 18:07 . init
package gen
import (
sql2 "database/sql"
"gitee.com/mosache/YFrame/tools/Y/model/db"
)
func getColumnInfo(database string, tables []string) ([]*ColumnInfoModel, error) {
r := make([]*ColumnInfoModel, 0)
sql := `
SELECT
c.TABLE_NAME AS table_name,
c.COLUMN_NAME AS column_name,
c.DATA_TYPE AS data_type,
c.COLUMN_TYPE AS column_type,
IF(c.COLUMN_KEY = 'PRI',1,2) AS is_primary_key,
c.COLUMN_COMMENT AS column_comment,
c.ORDINAL_POSITION AS position,
t.TABLE_COMMENT AS table_comment
FROM
information_schema.COLUMNS AS c
LEFT JOIN information_schema.TABLES AS t ON t.TABLE_NAME = c.TABLE_NAME AND t.TABLE_SCHEMA = @database
WHERE
c.TABLE_SCHEMA = @database
`
if len(tables) > 0 {
sql += "AND c.TABLE_NAME IN @tables "
}
sql += "ORDER BY c.TABLE_NAME,c.ORDINAL_POSITION"
if err := db.DB.Raw(sql, sql2.Named("database", database),
sql2.Named("tables", tables)).Scan(&r).Error; err != nil {
return nil, err
}
return r, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mosache/YFrame.git
git@gitee.com:mosache/YFrame.git
mosache
YFrame
YFrame
v0.1.38

搜索帮助

344bd9b3 5694891 D2dac590 5694891