當前位置: 首頁>>代碼示例>>Golang>>正文


Golang DB.Ping方法代碼示例

本文整理匯總了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
}
開發者ID:ory-am,項目名稱:ladon,代碼行數:25,代碼來源:manager_test.go

示例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)
}
開發者ID:ory-am,項目名稱:workshop-dbg,代碼行數:27,代碼來源:postgres_test.go

示例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
}
開發者ID:quorumsco,項目名稱:users,代碼行數:26,代碼來源:databases.go

示例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
}
開發者ID:svaroqui,項目名稱:mariadb-tools,代碼行數:23,代碼來源:dbhelper.go


注:本文中的github.com/jmoiron/sqlx.DB.Ping方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。