diff --git a/system.go b/system.go index bb782b2..3b534ae 100644 --- a/system.go +++ b/system.go @@ -35,3 +35,21 @@ func (sd *SystemDao) GetTableList(dbInstance *gorm.DB) ([]string, error) { } return result, nil } + +// GetCreateTableSQL 获取建表SQL +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:58 2022/5/15 +func (sd *SystemDao) GetCreateTableSQL(dbInstance *gorm.DB, table string) (string, error) { + var ( + err error + result string + ) + + if err = dbInstance.Raw("SHOW CREATE TABLE " + table).Scan(&result).Error; nil != err { + err = dbInstance.Exec("SHOW CREATE TABLE `" + table + "`;").Row().Scan(&result) + return "", err + } + return result, nil +}