context.go 682 B

1234567891011121314151617181920212223242526
  1. // Copyright 2017 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build go1.8
  5. package xorm
  6. import "context"
  7. // PingContext tests if database is alive
  8. func (engine *Engine) PingContext(ctx context.Context) error {
  9. session := engine.NewSession()
  10. defer session.Close()
  11. return session.PingContext(ctx)
  12. }
  13. // PingContext test if database is ok
  14. func (session *Session) PingContext(ctx context.Context) error {
  15. if session.isAutoClose {
  16. defer session.Close()
  17. }
  18. session.engine.logger.Infof("PING DATABASE %v", session.engine.DriverName())
  19. return session.DB().PingContext(ctx)
  20. }