You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

engine_context.go 746B

12345678910111213141516171819202122232425262728
  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. // +build go1.8
  5. package xorm
  6. import "context"
  7. // Context creates a session with the context
  8. func (engine *Engine) Context(ctx context.Context) *Session {
  9. session := engine.NewSession()
  10. session.isAutoClose = true
  11. return session.Context(ctx)
  12. }
  13. // SetDefaultContext set the default context
  14. func (engine *Engine) SetDefaultContext(ctx context.Context) {
  15. engine.defaultContext = ctx
  16. }
  17. // PingContext tests if database is alive
  18. func (engine *Engine) PingContext(ctx context.Context) error {
  19. session := engine.NewSession()
  20. defer session.Close()
  21. return session.PingContext(ctx)
  22. }