add schema deploy module

This commit is contained in:
Jay
2018-09-19 22:06:27 +08:00
parent a43bf98e21
commit ee12feda5d
5 changed files with 141 additions and 8 deletions
+8 -1
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"git.trj.tw/golang/mtfosbot/module/config"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
@@ -13,7 +14,8 @@ var x *sqlx.DB
// NewDB - connect to database
func NewDB() (*sqlx.DB, error) {
var err error
connStr := fmt.Sprintf("user=%s host=%s sslmode=disable dbname=%s port=%d", "postgres", "localhost", "mtfosbot", 5432)
conf := config.GetConf()
connStr := fmt.Sprintf("user=%s password=%s host=%s sslmode=disable dbname=%s port=%d", conf.Database.User, conf.Database.Pass, conf.Database.Host, conf.Database.DB, conf.Database.Port)
x, err = sqlx.Connect("postgres", connStr)
if err != nil {
log.Fatal(err)
@@ -26,3 +28,8 @@ func NewDB() (*sqlx.DB, error) {
}
return x, err
}
// GetDB -
func GetDB() *sqlx.DB {
return x
}