db

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFetchSize = 1000

Variables

This section is empty.

Functions

func Default

func Default() ctx.ServicePackage

func IsErrNotFound

func IsErrNotFound(err error) bool

func SessionContextReturning

func SessionContextReturning[T any](context context.Context, connection Connection, sessionFn func(session *Session) (T, error)) (T, error)

func SessionContextStream added in v0.3.2

func SessionContextStream[T any](ctx context.Context, connection Connection, fetchSize int, selectFn func(session *gorm.DB) *gorm.DB) channels.StreamingChan[T]

func SessionContextTxReturning

func SessionContextTxReturning[T any](context context.Context, connection Connection, txFn func(session *Session) (T, error)) (T, error)

func SessionReturning

func SessionReturning[T any](connection Connection, sessionFn func(session *Session) (T, error)) (T, error)

func SessionStream added in v0.3.2

func SessionStream[T any](connection Connection, fetchSize int, selectFn func(session *gorm.DB) *gorm.DB) channels.StreamingChan[T]

func SessionTxReturning

func SessionTxReturning[T any](connection Connection, txFn func(session *Session) (T, error)) (T, error)

func TxReturning

func TxReturning[T any](session *Session, txFn func(session *Session) (T, error)) (T, error)

Types

type Connection

type Connection interface {
	Init()
	AutoMigrate(models ...any)
	Session(session func(session *Session) error) error
	SessionContext(context context.Context, session func(session *Session) error) error
	Stats() (sql.DBStats, error)
	Check() error
	Health() health.ServiceHealth
}

func NewConnection

func NewConnection(name string, configPrefix string, isDefault bool, isCritical bool) Connection

type Paginator

type Paginator interface {
	Scope() func(db *gorm.DB) *gorm.DB
	OffsetResult(result *gorm.DB)
	HasNext() bool
	Limit() int
	Offset() int
}

func NewPaginator

func NewPaginator(fetchSize int) Paginator

type Session

type Session struct {
	context.Context
	*gorm.DB
	// contains filtered or unexported fields
}

func (*Session) LockForUpdate

func (s *Session) LockForUpdate() *gorm.DB

func (*Session) Tx

func (s *Session) Tx(txFunc func(session *Session) error) error

Jump to

Keyboard shortcuts

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