xorm_context

package module
v0.0.0-...-12482f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrCancelledf

func ErrCancelledf(format string, args ...interface{}) error

ErrCancelledf returns an ErrCancelled for the provided format and args

func GetEngine

func GetEngine(ctx context.Context) xorm.Interface

GetEngine will get a db Engine from this context or return an Engine restricted to this context

func InTransaction

func InTransaction(ctx context.Context) bool

InTransaction returns true if the engine is in a transaction otherwise return false

func IsErrCancelled

func IsErrCancelled(err error) bool

IsErrCancelled checks if an error is a ErrCancelled.

func IsErrNotExist

func IsErrNotExist(err error) bool

IsErrNotExist checks if an error is an ErrNotExist

func SetDefaultEngine

func SetDefaultEngine(ctx context.Context, eng *xorm.Engine)

SetDefaultEngine sets the default engine for db

func TxContext

func TxContext(parentCtx context.Context) (*Context, Committer, error)

TxContext represents a transaction Context, it will reuse the existing transaction in the parent context or create a new one.

func UnsetDefaultEngine

func UnsetDefaultEngine()

UnsetDefaultEngine closes and unsets the default engine We hope the SetDefaultEngine and UnsetDefaultEngine can be paired, but it's impossible now, there are many calls to InitEngine -> SetDefaultEngine directly to overwrite the `x` and DefaultContext without close Global database engine related functions are all racy and there is no graceful close right now.

func WithTx

func WithTx(parentCtx context.Context, f func(ctx context.Context) error) error

WithTx represents executing database operations on a transaction, if the transaction exist, this function will reuse it otherwise will create a new one and close it when finished.

Types

type Committer

type Committer interface {
	Commit() error
	Close() error
}

Committer represents an interface to Commit or Close the Context

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

Context represents a db context

func (*Context) Engine

func (ctx *Context) Engine() xorm.Interface

Engine returns db engine

func (*Context) InTransaction

func (ctx *Context) InTransaction() bool

InTransaction if context is in a transaction

func (*Context) Value

func (ctx *Context) Value(key interface{}) interface{}

Value shadows Value for context.Context but allows us to get ourselves and an Engined object

func (*Context) WithContext

func (ctx *Context) WithContext(other context.Context) *Context

WithContext returns this engine tied to this context

type Engined

type Engined interface {
	Engine() xorm.Interface
}

Engined structs provide an Engine

type ErrCancelled

type ErrCancelled struct {
	Message string
}

ErrCancelled represents an error due to context cancellation

func (ErrCancelled) Error

func (err ErrCancelled) Error() string

type ErrNotExist

type ErrNotExist struct {
	Resource string
	ID       int64
}

ErrNotExist represents a non-exist error.

func (ErrNotExist) Error

func (err ErrNotExist) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL