本文整理汇总了Golang中github.com/concourse/atc/db.Conn类的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Conn类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: LockDBAndMigrate
func LockDBAndMigrate(logger lager.Logger, sqlDriver string, sqlDataSource string) (db.Conn, error) {
var err error
var dbLockConn db.Conn
var dbConn db.Conn
for {
dbLockConn, err = db.WrapWithError(sql.Open(sqlDriver, sqlDataSource))
if err != nil {
if strings.Contains(err.Error(), " dial ") {
logger.Error("failed-to-open-db-retrying", err)
time.Sleep(5 * time.Second)
continue
}
return nil, err
}
break
}
lockName := crc32.ChecksumIEEE([]byte(sqlDriver + sqlDataSource))
for {
_, err = dbLockConn.Exec(`select pg_advisory_lock($1)`, lockName)
if err != nil {
logger.Error("failed-to-acquire-lock-retrying", err)
time.Sleep(5 * time.Second)
continue
}
logger.Info("migration-lock-acquired")
migrations := Translogrifier(logger, Migrations)
dbConn, err = db.WrapWithError(migration.OpenWith(sqlDriver, sqlDataSource, migrations, safeGetVersion, safeSetVersion))
if err != nil {
logger.Fatal("failed-to-run-migrations", err)
}
_, err = dbLockConn.Exec(`select pg_advisory_unlock($1)`, lockName)
if err != nil {
logger.Error("failed-to-release-lock", err)
}
dbLockConn.Close()
break
}
return dbConn, nil
}
开发者ID:xoebus,项目名称:checkin,代码行数:48,代码来源:lock_and_migrate.go
示例2:
package db_test
import (
"time"
"github.com/concourse/atc/db"
"github.com/concourse/atc/db/fakes"
"github.com/lib/pq"
"github.com/pivotal-golang/lager/lagertest"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("PipelineDBFactory", func() {
var dbConn db.Conn
var listener *pq.Listener
var pipelineDBFactory db.PipelineDBFactory
var pipelinesDB *fakes.FakePipelinesDB
BeforeEach(func() {
postgresRunner.Truncate()
dbConn = db.Wrap(postgresRunner.Open())
listener = pq.NewListener(postgresRunner.DataSourceName(), time.Second, time.Minute, nil)
Eventually(listener.Ping, 5*time.Second).ShouldNot(HaveOccurred())
bus := db.NewNotificationsBus(listener, dbConn)
开发者ID:pcfdev-forks,项目名称:atc,代码行数:30,代码来源:pipeline_db_factory_test.go
示例3:
package metric_test
import (
"errors"
"github.com/concourse/atc/db"
"github.com/concourse/atc/db/fakes"
"github.com/concourse/atc/metric"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Counting Database Queries", func() {
var (
underlyingConn *fakes.FakeConn
countingConn db.Conn
)
BeforeEach(func() {
underlyingConn = new(fakes.FakeConn)
countingConn = metric.CountQueries(underlyingConn)
})
AfterEach(func() {
err := countingConn.Close()
Expect(err).NotTo(HaveOccurred())
})
It("passes through calls to the underlying connection", func() {
countingConn.Ping()
开发者ID:pcfdev-forks,项目名称:atc,代码行数:31,代码来源:query_counter_test.go
示例4:
"time"
"github.com/concourse/atc/db"
"github.com/concourse/atc/db/fakes"
"github.com/pivotal-golang/lager/lagertest"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
)
var _ = Describe("Explain", func() {
var (
logger *lagertest.TestLogger
underlyingConn *fakes.FakeConn
explainConn db.Conn
)
BeforeEach(func() {
logger = lagertest.NewTestLogger("explain")
underlyingConn = new(fakes.FakeConn)
explainConn = db.Explain(logger, underlyingConn, 100*time.Millisecond)
})
AfterEach(func() {
err := explainConn.Close()
Ω(err).ShouldNot(HaveOccurred())
})
It("passes through calls to the underlying connection", func() {
开发者ID:utako,项目名称:atc,代码行数:31,代码来源:explain_db_test.go
注:本文中的github.com/concourse/atc/db.Conn类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论