[feature]:支持Sqlite数据库 (#1467)

* add sqlite3 support

* 修改gorm.io/driver/sqlite 为 github.com/glebarez/sqlite 适配windows用户无cgo环境

---------

Co-authored-by: Kafumio <linzehong1_2020@qq.com>
Co-authored-by: Kafumio <73083337+Kafumio@users.noreply.github.com>
Co-authored-by: sliverhorn <sliver_horn@qq.com>
This commit is contained in:
奇淼(piexlmax
2023-06-30 19:18:20 +08:00
committed by GitHub
parent 7ababb626b
commit bd3931d62d
17 changed files with 366 additions and 33 deletions

View File

@@ -7,12 +7,13 @@ import (
)
type InitDB struct {
DBType string `json:"dbType"` // 数据库类型
Host string `json:"host"` // 服务器地址
Port string `json:"port"` // 数据库连接端口
UserName string `json:"userName" binding:"required"` // 数据库用户名
Password string `json:"password"` // 数据库密码
DBName string `json:"dbName" binding:"required"` // 数据库名
DBType string `json:"dbType"` // 数据库类型
Host string `json:"host"` // 服务器地址
Port string `json:"port"` // 数据库连接端口
UserName string `json:"userName"` // 数据库用户名
Password string `json:"password"` // 数据库密码
DBName string `json:"dbName" binding:"required"` // 数据库名
DBPath string `json:"dbPath"` // sqlite数据库文件路径
}
// MysqlEmptyDsn msyql 空数据库 建库链接
@@ -39,6 +40,12 @@ func (i *InitDB) PgsqlEmptyDsn() string {
return "host=" + i.Host + " user=" + i.UserName + " password=" + i.Password + " port=" + i.Port + " dbname=" + "postgres" + " " + "sslmode=disable TimeZone=Asia/Shanghai"
}
// SqliteEmptyDsn sqlite 空数据库 建库链接
// Author Kafumio
func (i *InitDB) SqliteEmptyDsn() string {
return i.DBPath + "\\" + i.DBName + ".db"
}
// ToMysqlConfig 转换 config.Mysql
// Author [SliverHorn](https://github.com/SliverHorn)
func (i *InitDB) ToMysqlConfig() config.Mysql {
@@ -74,3 +81,21 @@ func (i *InitDB) ToPgsqlConfig() config.Pgsql {
},
}
}
// ToSqliteConfig 转换 config.Sqlite
// Author [Kafumio](https://github.com/Kafumio)
func (i *InitDB) ToSqliteConfig() config.Sqlite {
return config.Sqlite{
GeneralDB: config.GeneralDB{
Path: i.DBPath,
Port: i.Port,
Dbname: i.DBName,
Username: i.UserName,
Password: i.Password,
MaxIdleConns: 10,
MaxOpenConns: 100,
LogMode: "error",
Config: "",
},
}
}