feat:完善项目
This commit is contained in:
7
serve/orm/logic/engine.go
Normal file
7
serve/orm/logic/engine.go
Normal file
@ -0,0 +1,7 @@
|
||||
package logic
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type IEngine interface {
|
||||
DSN() gorm.Dialector
|
||||
}
|
20
serve/orm/logic/mysql.go
Normal file
20
serve/orm/logic/mysql.go
Normal file
@ -0,0 +1,20 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Mysql struct {
|
||||
User, Password, Host string
|
||||
Port int
|
||||
DBName, Parameters string
|
||||
}
|
||||
|
||||
func (this *Mysql) DSN() gorm.Dialector {
|
||||
return mysql.Open(fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?%s",
|
||||
this.User, this.Password, this.Host, this.Port, this.DBName, this.Parameters,
|
||||
))
|
||||
}
|
19
serve/orm/logic/sqlite.go
Normal file
19
serve/orm/logic/sqlite.go
Normal file
@ -0,0 +1,19 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"github.com/belief428/gorm-engine/tools"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Sqlite struct {
|
||||
Path string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (this *Sqlite) DSN() gorm.Dialector {
|
||||
if isExist, _ := tools.PathExists(this.Path); !isExist {
|
||||
_ = tools.MkdirAll(this.Path)
|
||||
}
|
||||
return sqlite.Open(this.Path + "/" + this.Name)
|
||||
}
|
Reference in New Issue
Block a user