mirror of
https://github.com/ZSCNetSupportDept/scheduler.git
synced 2025-10-28 20:45:05 +08:00
add 数据库 Web框架 初步 支持
This commit is contained in:
32
database/database.go
Normal file
32
database/database.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"os"
|
||||
"zsxyww.com/scheduler/config"
|
||||
"zsxyww.com/scheduler/model"
|
||||
)
|
||||
|
||||
var err error
|
||||
|
||||
func Connect() {
|
||||
if config.DB.Type == "SQLite" {
|
||||
connectSQLite()
|
||||
} else {
|
||||
fmt.Println("sorry,we support SQLite only so far,check **DB.Type** entry in the config file")
|
||||
os.Exit(1)
|
||||
}
|
||||
Main.AutoMigrate(&model.Member{})
|
||||
}
|
||||
|
||||
func connectSQLite() {
|
||||
Main, err = gorm.Open(sqlite.Open(config.DB.Path), &gorm.Config{})
|
||||
if err != nil {
|
||||
fmt.Printf("error in connecting to SQLite:")
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
|
||||
}
|
||||
}
|
||||
7
database/model.go
Normal file
7
database/model.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var Main *gorm.DB //Main database connection
|
||||
Reference in New Issue
Block a user