Matheus Sampaio Queiroga
9d16350e2d
Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
38 lines
853 B
Go
38 lines
853 B
Go
package base
|
|
|
|
import (
|
|
_ "modernc.org/sqlite"
|
|
"xorm.io/xorm"
|
|
"xorm.io/xorm/log"
|
|
|
|
bdsuser "sirherobrine23.com.br/go-bds/bds-dashboard/models/user"
|
|
)
|
|
|
|
type BuildDB interface {
|
|
Migrate(conn xorm.EngineInterface, oldVersion string) (string, error) // Migrate function, always call if struct ared exist in database
|
|
Create(conn xorm.EngineInterface) error // Function to crate database
|
|
Connect(conn xorm.EngineInterface) // Save engine connection
|
|
}
|
|
|
|
var DBUps = []BuildDB{
|
|
&bdsuser.User{},
|
|
}
|
|
|
|
func DBConnect() error {
|
|
eng, err := xorm.NewEngine("sqlite", "./test.db")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
eng.ShowSQL(true)
|
|
eng.Logger().SetLevel(log.LOG_DEBUG)
|
|
|
|
for _, db := range DBUps {
|
|
if err := db.Create(eng); err != nil {
|
|
return err
|
|
}
|
|
go db.Connect(eng)
|
|
}
|
|
|
|
return nil
|
|
}
|