本文整理匯總了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
}