feat✨: 添加sqlserver支持
This commit is contained in:
1 parent
02b62a288d
commit
d02b52f383
8 files changed
+366
-38
No files matched your search
@@ -1,7 +1,6 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go-admin/common/global"
|
||||
"gorm.io/gorm"
|
||||
@@ -13,40 +12,19 @@ import (
|
||||
func InitDb(db *gorm.DB) (err error) {
|
||||
filePath := "config/db.sql"
|
||||
if global.Driver == "postgres" {
|
||||
err = ExecSql(db, filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filePath = "config/pg.sql"
|
||||
err = ExecSql(db, filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if global.Driver == "mysql" {
|
||||
filePath = "config/db-begin-mysql.sql"
|
||||
err = ExecSql(db, filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filePath = "config/db.sql"
|
||||
err = ExecSql(db, filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filePath = "config/db-end-mysql.sql"
|
||||
err = ExecSql(db, filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if global.Driver == "sqlite3" {
|
||||
err = ExecSql(db, filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return errors.New("database type is not supported")
|
||||
err = ExecSql(db, filePath)
|
||||
}
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func ExecSql(db *gorm.DB, filePath string) error {
|
||||
|
||||
@@ -11,13 +11,13 @@ type SysUser struct {
|
||||
Password string `json:"-" gorm:"type:varchar(128);comment:密码"`
|
||||
NickName string `json:"nickName" gorm:"type:varchar(128);comment:昵称"`
|
||||
Phone string `json:"phone" gorm:"type:varchar(11);comment:手机号"`
|
||||
RoleId int `json:"roleId" gorm:"type:bigint(20);comment:角色ID"`
|
||||
RoleId int `json:"roleId" gorm:"type:bigint;comment:角色ID"`
|
||||
Salt string `json:"-" gorm:"type:varchar(255);comment:加盐"`
|
||||
Avatar string `json:"avatar" gorm:"type:varchar(255);comment:头像"`
|
||||
Sex string `json:"sex" gorm:"type:varchar(255);comment:性别"`
|
||||
Email string `json:"email" gorm:"type:varchar(128);comment:邮箱"`
|
||||
DeptId int `json:"deptId" gorm:"type:bigint(20);comment:部门"`
|
||||
PostId int `json:"postId" gorm:"type:bigint(20);comment:岗位"`
|
||||
DeptId int `json:"deptId" gorm:"type:bigint;comment:部门"`
|
||||
PostId int `json:"postId" gorm:"type:bigint;comment:岗位"`
|
||||
Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"`
|
||||
Status string `json:"status" gorm:"type:varchar(4);comment:状态"`
|
||||
ControlBy
|
||||
@@ -45,4 +45,4 @@ func (e *SysUser) Encrypt() (err error) {
|
||||
|
||||
func (e *SysUser) BeforeCreate(_ *gorm.DB) error {
|
||||
return e.Encrypt()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user