本文整理汇总了Golang中github.com/jmoiron/sqlx.DB.Ping方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.Ping方法的具体用法?Golang DB.Ping怎么用?Golang DB.Ping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jmoiron/sqlx.DB
的用法示例。
在下文中一共展示了DB.Ping方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: connectMySQL
func connectMySQL() {
var db *sqlx.DB
c, err := dockertest.ConnectToMySQL(15, time.Second, func(url string) bool {
var err error
db, err = sqlx.Open("mysql", url)
if err != nil {
log.Printf("Got error in mysql connector: %s", err)
return false
}
return db.Ping() == nil
})
if err != nil {
log.Fatalf("Could not connect to database: %s", err)
}
containers = append(containers, c)
s := NewSQLManager(db, nil)
if err = s.CreateSchemas(); err != nil {
log.Fatalf("Could not create mysql schema: %v", err)
}
managers["mysql"] = s
}
示例2: TestMain
func TestMain(m *testing.M) {
var db *sqlx.DB
var err error
var c dockertest.ContainerID
if c, err = dockertest.ConnectToPostgreSQL(15, time.Second, func(url string) bool {
var err error
db, err = sqlx.Open("postgres", url)
if err != nil {
return false
}
return db.Ping() == nil
}); err != nil {
log.Fatalf("Could not connect to database: %s", err)
}
s = &PostgresStore{DB: db}
if err := s.CreateSchemas(); err != nil {
log.Fatalf("Could not set up schemas: %v", err)
}
if err := s.CreateSchemas(); err != nil {
log.Fatalf("Schema did fail on second time: %v", err)
}
result := m.Run()
c.KillRemove()
os.Exit(result)
}
示例3: InitSQLX
func InitSQLX(dialect, args string) (*sqlx.DB, error) {
var db *sqlx.DB
var err error
var i int
retry:
for {
db, err = sqlx.Connect(dialect, args)
switch {
case err == nil:
break retry
case i >= RETRY:
return nil, err
default:
logs.Error(err)
i++
}
time.Sleep(TIMEOUT)
}
if db.Ping() != nil {
return db, err
}
return db, nil
}
示例4: CheckSlavePrerequisites
/* Check for a list of slave prerequisites.
- Slave is connected
- Binary log on
- Connected to master
- No replication filters
*/
func CheckSlavePrerequisites(db *sqlx.DB, s string) bool {
if debug {
log.Printf("CheckSlavePrerequisites called")
}
err := db.Ping()
/* If slave is not online, skip to next iteration */
if err != nil {
log.Printf("WARN : Slave %s is offline. Skipping", s)
return false
}
vars, _ := GetVariables(db)
if vars["LOG_BIN"] == "OFF" {
log.Printf("WARN : Binary log off. Slave %s cannot be used as candidate master.", s)
return false
}
return true
}