3 Star 1 Fork 915

高煜涛/gin-vue-admin

forked from pixel/gin-vue-admin 
Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
gorm_sqlite.go 1016 Bytes
Copy Edit Raw Blame History
高煜涛 authored 2023-07-24 00:14 . 23/07/24
package initialize
import (
"gitee.com/g-qs/gin-vue-admin/server/config"
"gitee.com/g-qs/gin-vue-admin/server/global"
"gitee.com/g-qs/gin-vue-admin/server/initialize/internal"
"github.com/glebarez/sqlite"
"gorm.io/gorm"
)
// GormSqlite 初始化Sqlite数据库
func GormSqlite() *gorm.DB {
s := global.GVA_CONFIG.Sqlite
if s.Dbname == "" {
return nil
}
if db, err := gorm.Open(sqlite.Open(s.Dsn()), internal.Gorm.Config(s.Prefix, s.Singular)); err != nil {
panic(err)
} else {
sqlDB, _ := db.DB()
sqlDB.SetMaxIdleConns(s.MaxIdleConns)
sqlDB.SetMaxOpenConns(s.MaxOpenConns)
return db
}
}
// GormSqliteByConfig 初始化Sqlite数据库用过传入配置
func GormSqliteByConfig(s config.Sqlite) *gorm.DB {
if s.Dbname == "" {
return nil
}
if db, err := gorm.Open(sqlite.Open(s.Dsn()), internal.Gorm.Config(s.Prefix, s.Singular)); err != nil {
panic(err)
} else {
sqlDB, _ := db.DB()
sqlDB.SetMaxIdleConns(s.MaxIdleConns)
sqlDB.SetMaxOpenConns(s.MaxOpenConns)
return db
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/g-qs/gin-vue-admin.git
git@gitee.com:g-qs/gin-vue-admin.git
g-qs
gin-vue-admin
gin-vue-admin
a5c0f301b910

Search

0d507c66 1850385 C8b1a773 1850385