session_context.go 615 B

1234567891011121314151617181920212223
  1. // Copyright 2019 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. package xorm
  5. import "context"
  6. // Context sets the context on this session
  7. func (session *Session) Context(ctx context.Context) *Session {
  8. session.ctx = ctx
  9. return session
  10. }
  11. // PingContext test if database is ok
  12. func (session *Session) PingContext(ctx context.Context) error {
  13. if session.isAutoClose {
  14. defer session.Close()
  15. }
  16. session.engine.logger.Infof("PING DATABASE %v", session.engine.DriverName())
  17. return session.DB().PingContext(ctx)
  18. }