Added sqlite as database option
the build failed
Details
the build failed
Details
This commit is contained in:
parent
111ffe687d
commit
9e6ddafe7e
|
@ -4,11 +4,14 @@ JWTSecret = blablaGEHEMIN§)!§
|
||||||
Interface = :8080
|
Interface = :8080
|
||||||
|
|
||||||
[Database]
|
[Database]
|
||||||
|
Type = mysql
|
||||||
User = root
|
User = root
|
||||||
Password = supersecret
|
Password = supersecret
|
||||||
Host = 127.0.0.1
|
Host = 127.0.0.1
|
||||||
Database = library
|
Database = library
|
||||||
ShowQueries = false
|
ShowQueries = false
|
||||||
|
; When using sqlite, this is the path where to store the data
|
||||||
|
; Path = ./library.db
|
||||||
|
|
||||||
; First user to be created, on every startup the program checks if he exists, if not it creates it
|
; First user to be created, on every startup the program checks if he exists, if not it creates it
|
||||||
[User]
|
[User]
|
||||||
|
|
|
@ -8,10 +8,12 @@ import (
|
||||||
// ConfigStruct holds the config struct
|
// ConfigStruct holds the config struct
|
||||||
type ConfigStruct struct {
|
type ConfigStruct struct {
|
||||||
Database struct {
|
Database struct {
|
||||||
|
Type string
|
||||||
Host string
|
Host string
|
||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
Database string
|
Database string
|
||||||
|
Path string
|
||||||
ShowQueries bool
|
ShowQueries bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
//_ "github.com/mattn/go-sqlite3" // Because.
|
_ "github.com/mattn/go-sqlite3" // Because.
|
||||||
_ "github.com/go-sql-driver/mysql" // Because.
|
_ "github.com/go-sql-driver/mysql" // Because.
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
|
@ -11,10 +11,19 @@ import (
|
||||||
var x *xorm.Engine
|
var x *xorm.Engine
|
||||||
|
|
||||||
func getEngine() (*xorm.Engine, error) {
|
func getEngine() (*xorm.Engine, error) {
|
||||||
connStr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true",
|
// Use Mysql if set
|
||||||
Config.Database.User, Config.Database.Password, Config.Database.Host, Config.Database.Database)
|
if Config.Database.Type == "mysql" {
|
||||||
return xorm.NewEngine("mysql", connStr)
|
connStr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true",
|
||||||
//return xorm.NewEngine("sqlite3", "./db.db")
|
Config.Database.User, Config.Database.Password, Config.Database.Host, Config.Database.Database)
|
||||||
|
return xorm.NewEngine("mysql", connStr)
|
||||||
|
} else {
|
||||||
|
// Otherwise use sqlite
|
||||||
|
path := Config.Database.Path
|
||||||
|
if path == "" {
|
||||||
|
path = "./db.db"
|
||||||
|
}
|
||||||
|
return xorm.NewEngine("sqlite3", path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetEngine sets the xorm.Engine
|
// SetEngine sets the xorm.Engine
|
||||||
|
@ -40,6 +49,7 @@ func SetEngine() (err error) {
|
||||||
x.Sync(&Quantity{})
|
x.Sync(&Quantity{})
|
||||||
x.Sync(&quantityRelation{})
|
x.Sync(&quantityRelation{})
|
||||||
x.Sync(&Item{})
|
x.Sync(&Item{})
|
||||||
|
x.Sync(&UserLog{})
|
||||||
|
|
||||||
x.ShowSQL(Config.Database.ShowQueries)
|
x.ShowSQL(Config.Database.ShowQueries)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue