123456789101112131415161718192021 |
- package util
- import (
- "database/sql"
- "fmt"
- "sync-block/er"
- _ "github.com/go-sql-driver/mysql"
- )
- func ConnectDb(host, id, pw, dbName string) *sql.DB {
- db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?parseTime=true",
- id, pw, host, dbName))
- er.Check(err)
- er.Check(db.Ping())
- return db
- }
- func NewNoopDB() DB {
- return &NoopDB{}
- }
|