From 92d79d2733fcc233ce0c8d6b775176afdef27a34 Mon Sep 17 00:00:00 2001 From: Yun Date: Thu, 14 Mar 2024 23:12:37 +0800 Subject: [PATCH] =?UTF-8?q?option=E5=88=9D=E5=A7=8B=E5=8C=96=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E8=B5=8B=E4=BA=88=E9=83=A8=E5=88=86=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- options.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/options.go b/options.go index a5705cc..a4720ae 100644 --- a/options.go +++ b/options.go @@ -5,7 +5,7 @@ type clientOptions struct { Mysql *MysqlOptions Sqlite *SqliteOptions Prefix string // 表名前缀,`Article` 的表名应该是 `it_articles` - SingularTable bool // 使用单数表名,启用该选项,此时,`Article` 的表名应该是 `it_article` + SingularTable bool // 使用单数表名,启用该选项,此时,`Article` 的表名应该是 `it_article` } type MysqlOptions struct { @@ -38,18 +38,27 @@ func SetMysql(user, password, host, database string, port int) Option { Database: database, Password: password, } + if o.Mysql.Port == 0 { + o.Mysql.Port = 3306 + } } } +// 使用sqlite数据库 func SetSqlite(dbPath string) Option { return func(o *clientOptions) { o.Db = "sqlite" o.Sqlite = &SqliteOptions{ DbPath: dbPath, } + if o.Sqlite.DbPath == "" { + o.Sqlite.DbPath = "sqlite.db" + } } } + +// 表名前缀 func SetTablePrefix(perfix string) Option { return func(o *clientOptions) { o.Prefix = perfix