From b2dcef055390b1cc9ea613d19ce83fcf829a3ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 15 May 2022 21:29:39 +0800 Subject: [PATCH] save code --- system.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 +}