From 72aa931caad6d2def79d9f6dd9f281650d023f34 Mon Sep 17 00:00:00 2001 From: tiglog Date: Thu, 17 Aug 2023 19:21:21 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=94=B9=E7=94=A8=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E6=9A=B4=E9=9C=B2=E5=8F=A5=E6=9F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gdb/sqldb/db.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gdb/sqldb/db.go b/gdb/sqldb/db.go index c36378d..32fa4fc 100644 --- a/gdb/sqldb/db.go +++ b/gdb/sqldb/db.go @@ -21,7 +21,7 @@ import ( "time" ) -var DM *DbMap +var dm *DbMap type DbOption struct { Type string @@ -65,13 +65,24 @@ func InitDb(opt DbOption) error { default: return errors.New("unrecognized database driver") } - DM = &DbMap{ + dm = &DbMap{ Db: db, Dialect: dialect, } return nil } +// 通过函数暴露句柄 +func GetDm() *DbMap { + if dm == nil { + InitDb(DbOption{ + Type: "sqlite3", + Dsn: ":memory:", + }) + } + return dm +} + // DbMap is the root sqldb mapping object. Create one of these for each // database schema you wish to map. Each DbMap contains a list of // mapped tables.