feat(ReverseEngine):初始化工程
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"ReverseEngine/entity"
|
||||
"database/sql"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DbUtil struct {
|
||||
}
|
||||
|
||||
func FindColumnMessage(dbName string, tableName string, db *sql.DB) []entity.ColumnMessage {
|
||||
var cms []entity.ColumnMessage
|
||||
|
||||
row, err := db.Query(strings.Join([]string{"show full columns from ", dbName, ".", tableName}, ""))
|
||||
if err != nil {
|
||||
panic("数据库查询出错:" + err.Error())
|
||||
}
|
||||
|
||||
for row.Next() {
|
||||
var cm entity.ColumnMessage
|
||||
err := row.Scan(&cm.Field, &cm.Type, &cm.Collation, &cm.Null, &cm.Key, &cm.Default, &cm.Extra, &cm.Privileges, &cm.Comment)
|
||||
if err != nil {
|
||||
panic("字段赋值错误了" + err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
cms = append(cms, cm)
|
||||
}
|
||||
|
||||
return cms
|
||||
}
|
||||
Reference in New Issue
Block a user