本文整理匯總了Golang中github.com/concourse/atc/db.Conn.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Close方法的具體用法?Golang Conn.Close怎麽用?Golang Conn.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/concourse/atc/db.Conn
的用法示例。
在下文中一共展示了Conn.Close方法的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
}
示例2:
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)
pipelinesDB = new(fakes.FakePipelinesDB)
pipelineDBFactory = db.NewPipelineDBFactory(lagertest.NewTestLogger("test"), dbConn, bus, pipelinesDB)
})
AfterEach(func() {
err := dbConn.Close()
Expect(err).NotTo(HaveOccurred())
err = listener.Close()
Expect(err).NotTo(HaveOccurred())
})
Describe("default pipeline", func() {
It("is the first one returned from the DB", func() {
savedPipelineOne := db.SavedPipeline{
ID: 1,
Pipeline: db.Pipeline{
Name: "a-pipeline",
},
}
示例3:
. "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()
Expect(underlyingConn.PingCallCount()).To(Equal(1))
})
It("returns the return values from the underlying connection", func() {
underlyingConn.PingReturns(errors.New("disaster"))
err := countingConn.Ping()
Expect(err).To(MatchError("disaster"))
})
示例4:
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() {
explainConn.Ping()
Ω(underlyingConn.PingCallCount()).To(Equal(1))
})
It("returns the return values from the underlying connection", func() {
underlyingConn.PingReturns(errors.New("disaster"))
err := explainConn.Ping()
Ω(err).Should(MatchError("disaster"))
})