db

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFetchSize = 1000

Variables

This section is empty.

Functions

func CloseConnection added in v0.6.0

func CloseConnection(connection Connection) error

CloseConnection closes a manually owned built-in connection. Container-managed connections invoke the same idempotent operation automatically during shutdown and disposal. Close calls may be repeated or concurrent. Manual Init and close phases remain serialized; operational calls may overlap a completed-generation restart and observe either inactive or fresh state.

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]

SessionContextStream streams paginated query results with one shared context for pool work, queries, page delivery, and terminal completion. Cancel ctx before abandoning the output.

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() error
	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