From f9e94c3769738d03abea6b40ad2bfd8c33ef771f 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, 9 Apr 2023 17:51:04 +0800 Subject: [PATCH] =?UTF-8?q?systemDao=E5=A2=9E=E5=8A=A0=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=8F=8A=E6=9F=A5=E7=9C=8B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=88=97=E8=A1=A8=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/system.go b/system.go index b656c16..c1151d6 100644 --- a/system.go +++ b/system.go @@ -21,6 +21,32 @@ import ( type SystemDao struct { } +// SelectDatabase 切换数据库 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 17:44 2023/4/9 +func (sd *SystemDao) SelectDatabase(dbInstance *gorm.DB, database string) error { + return dbInstance.Raw("USE " + database).Error +} + +// GetDatabaseList 获取数据库列表 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 17:46 2023/4/9 +func (sd *SystemDao) GetDatabaseList(dbInstance *gorm.DB) ([]string, error) { + var ( + err error + result []string + ) + + if err = dbInstance.Raw("SHOW DATABASES").Scan(&result).Error; nil != err { + return nil, err + } + return result, nil +} + // GetTableList 查询数据表 // // Author : go_developer@163.com<白茶清欢>