support sqlite
支持sqlite
This commit is contained in:
@@ -47,8 +47,8 @@ func fixForeignKey(list []genForeignKey, columuName string, result *[]model.Fore
|
||||
}
|
||||
}
|
||||
|
||||
// GetMysqlModel get model interface. 获取model接口
|
||||
func GetMysqlModel() model.IModel {
|
||||
// GetModel get model interface. 获取model接口
|
||||
func GetModel() model.IModel {
|
||||
//now just support mysql
|
||||
return &MySQLModel
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func (m *mysqlModel) GenModel() model.DBInfo {
|
||||
defer orm.OnDestoryDB()
|
||||
|
||||
var dbInfo model.DBInfo
|
||||
getPackageInfo(orm, &dbInfo)
|
||||
m.getPackageInfo(orm, &dbInfo)
|
||||
dbInfo.PackageName = m.GetPkgName()
|
||||
dbInfo.DbName = m.GetDbName()
|
||||
return dbInfo
|
||||
@@ -31,7 +31,7 @@ func (m *mysqlModel) GenModel() model.DBInfo {
|
||||
|
||||
// GetDbName get database name.获取数据库名字
|
||||
func (m *mysqlModel) GetDbName() string {
|
||||
return config.GetMysqlDbInfo().Database
|
||||
return config.GetDbInfo().Database
|
||||
}
|
||||
|
||||
// GetPkgName package names through config outdir configuration.通过config outdir 配置获取包名
|
||||
@@ -59,8 +59,8 @@ func (m *mysqlModel) GetPkgName() string {
|
||||
return pkgName
|
||||
}
|
||||
|
||||
func getPackageInfo(orm *mysqldb.MySqlDB, info *model.DBInfo) {
|
||||
tabls := getTables(orm) // get table and notes
|
||||
func (m *mysqlModel) getPackageInfo(orm *mysqldb.MySqlDB, info *model.DBInfo) {
|
||||
tabls := m.getTables(orm) // get table and notes
|
||||
// if m := config.GetTableList(); len(m) > 0 {
|
||||
// // 制定了表之后
|
||||
// newTabls := make(map[string]string)
|
||||
@@ -94,7 +94,7 @@ func getPackageInfo(orm *mysqldb.MySqlDB, info *model.DBInfo) {
|
||||
}
|
||||
|
||||
// build element.构造元素
|
||||
tab.Em = getTableElement(orm, tabName)
|
||||
tab.Em = m.getTableElement(orm, tabName)
|
||||
// --------end
|
||||
|
||||
info.TabList = append(info.TabList, tab)
|
||||
@@ -106,7 +106,7 @@ func getPackageInfo(orm *mysqldb.MySqlDB, info *model.DBInfo) {
|
||||
}
|
||||
|
||||
// getTableElement Get table columns and comments.获取表列及注释
|
||||
func getTableElement(orm *mysqldb.MySqlDB, tab string) (el []model.ColumnsInfo) {
|
||||
func (m *mysqlModel) getTableElement(orm *mysqldb.MySqlDB, tab string) (el []model.ColumnsInfo) {
|
||||
keyNameCount := make(map[string]int)
|
||||
KeyColumnMp := make(map[string][]keys)
|
||||
// get keys
|
||||
@@ -133,7 +133,7 @@ func getTableElement(orm *mysqldb.MySqlDB, tab string) (el []model.ColumnsInfo)
|
||||
var foreignKeyList []genForeignKey
|
||||
if config.GetIsForeignKey() {
|
||||
sql := fmt.Sprintf(`select table_schema as table_schema,table_name as table_name,column_name as column_name,referenced_table_schema as referenced_table_schema,referenced_table_name as referenced_table_name,referenced_column_name as referenced_column_name
|
||||
from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_schema = '%v' AND REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = '%v'`, config.GetMysqlDbInfo().Database, tab)
|
||||
from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_schema = '%v' AND REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = '%v'`, m.GetDbName(), tab)
|
||||
orm.Raw(sql).Scan(&foreignKeyList)
|
||||
}
|
||||
// ------------------end
|
||||
@@ -189,7 +189,7 @@ func getTableElement(orm *mysqldb.MySqlDB, tab string) (el []model.ColumnsInfo)
|
||||
}
|
||||
|
||||
// getTables Get columns and comments.获取表列及注释
|
||||
func getTables(orm *mysqldb.MySqlDB) map[string]string {
|
||||
func (m *mysqlModel) getTables(orm *mysqldb.MySqlDB) map[string]string {
|
||||
tbDesc := make(map[string]string)
|
||||
|
||||
// Get column names.获取列名
|
||||
@@ -212,7 +212,7 @@ func getTables(orm *mysqldb.MySqlDB) map[string]string {
|
||||
rows.Close()
|
||||
|
||||
// Get table annotations.获取表注释
|
||||
rows1, err := orm.Raw("SELECT TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES WHERE table_schema= '" + config.GetMysqlDbInfo().Database + "'").Rows()
|
||||
rows1, err := orm.Raw("SELECT TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES WHERE table_schema= '" + m.GetDbName() + "'").Rows()
|
||||
if err != nil {
|
||||
if !config.GetIsGUI() {
|
||||
fmt.Println(err)
|
||||
|
||||
Reference in New Issue
Block a user