[TASK] add database support
This commit is contained in:
parent
75a378a0cd
commit
eb75db5989
|
@ -1,16 +1,14 @@
|
||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Write *gorm.Database
|
Write *gorm.DB
|
||||||
Read *gorm.Database
|
Read *gorm.DB
|
||||||
config *Config
|
config *Config
|
||||||
models []interface{}
|
models []interface{}
|
||||||
)
|
)
|
||||||
|
@ -22,7 +20,7 @@ type Config struct {
|
||||||
ReadConnection string
|
ReadConnection string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Open(c Config) (err errors.Error) {
|
func Open(c Config) (err error) {
|
||||||
config = &c
|
config = &c
|
||||||
Write, err = gorm.Open(config.Type, config.Connection)
|
Write, err = gorm.Open(config.Type, config.Connection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
package database
|
package database
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,7 @@ import (
|
||||||
//Config the config File of this daemon
|
//Config the config File of this daemon
|
||||||
type Config struct {
|
type Config struct {
|
||||||
WebserverBind string
|
WebserverBind string
|
||||||
Database struct {
|
Database database.Config
|
||||||
Type string
|
|
||||||
Connection string
|
|
||||||
ReadConnection string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadConfigFile reads a config model from path of a yml file
|
// ReadConfigFile reads a config model from path of a yml file
|
||||||
|
|
Reference in New Issue