feat:完善项目

This commit is contained in:
henry
2021-09-28 11:47:19 +08:00
commit da7b3130fe
167 changed files with 456676 additions and 0 deletions

View 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
View 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
View 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)
}