db

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package db

Package db

Package db

Package db

Package db

Index

Constants

This section is empty.

Variables

View Source
var CheckPoint = fxtrategy.ProvideItem[ready.CheckPoint](newCheckpoint, ready.CPGroupName)

CheckPoint 数据库健康检测

Functions

This section is empty.

Types

type BaseMapper

type BaseMapper[T ModelConstraint] interface {
	SelectOne(t *T) (*T, error)
	Select(t *T) ([]T, error)
	SelectById(id uuid.UUID) (*T, error)

	GetPage(input page.InputInterface) (*page.Output[T], error)

	UpdateByPrimaryKeySelective(t *T) (int64, error)

	DeleteById(ids ...uuid.UUID) (int64, error)

	Insert(e *T) (int64, error)
	InsertBatch(list []T) (int64, error)

	Count(t *T) (int64, error)

	Transaction(f func(tx *gorm.DB) error) error

	GetConn() *gorm.DB

	GetSafeOrderBy(raw string) clause.OrderBy
}

func NewBaseMapper

func NewBaseMapper[T ModelConstraint](manager *Manager) BaseMapper[T]

type BaseMapperImpl

type BaseMapperImpl[T ModelConstraint] struct {
	// contains filtered or unexported fields
}

func (*BaseMapperImpl[T]) Count

func (m *BaseMapperImpl[T]) Count(t *T) (int64, error)

func (*BaseMapperImpl[T]) DeleteById

func (m *BaseMapperImpl[T]) DeleteById(ids ...uuid.UUID) (int64, error)

func (*BaseMapperImpl[T]) GetConn

func (m *BaseMapperImpl[T]) GetConn() *gorm.DB

func (*BaseMapperImpl[T]) GetPage

func (m *BaseMapperImpl[T]) GetPage(input page.InputInterface) (*page.Output[T], error)

func (*BaseMapperImpl[T]) GetSafeOrderBy added in v0.1.4

func (m *BaseMapperImpl[T]) GetSafeOrderBy(raw string) clause.OrderBy

func (*BaseMapperImpl[T]) Insert

func (m *BaseMapperImpl[T]) Insert(e *T) (int64, error)

func (*BaseMapperImpl[T]) InsertBatch

func (m *BaseMapperImpl[T]) InsertBatch(list []T) (int64, error)

func (*BaseMapperImpl[T]) Select

func (m *BaseMapperImpl[T]) Select(t *T) ([]T, error)

func (*BaseMapperImpl[T]) SelectById

func (m *BaseMapperImpl[T]) SelectById(id uuid.UUID) (*T, error)

func (*BaseMapperImpl[T]) SelectOne

func (m *BaseMapperImpl[T]) SelectOne(t *T) (*T, error)

func (*BaseMapperImpl[T]) Transaction

func (m *BaseMapperImpl[T]) Transaction(f func(tx *gorm.DB) error) error

func (*BaseMapperImpl[T]) UpdateByPrimaryKeySelective

func (m *BaseMapperImpl[T]) UpdateByPrimaryKeySelective(t *T) (int64, error)

type HardDeleteModel

type HardDeleteModel struct {
	CreatedAt time.Time `json:"createdAt" gorm:"type:timestamptz"`
	UpdatedAt time.Time `json:"updatedAt" gorm:"type:timestamptz"`
}

HardDeleteModel 适合需要硬删除的场景

func (HardDeleteModel) HasChanged

func (m HardDeleteModel) HasChanged() bool

func (HardDeleteModel) IsDel

func (m HardDeleteModel) IsDel() bool

type JSONB

type JSONB[T any] struct {
	// contains filtered or unexported fields
}

func NewJSONB

func NewJSONB[T any](t T) *JSONB[T]

func (*JSONB[T]) Get

func (j *JSONB[T]) Get() T

func (JSONB[T]) GormDataType

func (JSONB[T]) GormDataType() string

func (JSONB[T]) GormValue added in v0.1.1

func (j JSONB[T]) GormValue(_ context.Context, _ *gorm.DB) clause.Expr

GormValue 为 GORM 生成显式 jsonb cast,避免在缺少列类型上下文时被错误推断。

func (JSONB[T]) MarshalJSON

func (j JSONB[T]) MarshalJSON() ([]byte, error)

MarshalJSON returns m as the JSON encoding of m.

func (*JSONB[T]) Scan

func (j *JSONB[T]) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (*JSONB[T]) Set

func (j *JSONB[T]) Set(value T)

func (*JSONB[T]) UnmarshalJSON

func (j *JSONB[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data.

func (JSONB[T]) Value

func (j JSONB[T]) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,返回 JSON 文本而不是 []byte。 pgx simple protocol 会按 Go 类型做参数插值,[]byte 会被当成 bytea, 导致 jsonb 列写入失败或行为异常。

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 数据库连接管理 database/sql 级别的DB,Stmt都是并发安全的

func InitDataSource

func InitDataSource() (*Manager, error)

func (*Manager) GetDB

func (manager *Manager) GetDB() *gorm.DB

type Model

type Model struct {
	CreatedAt time.Time      `json:"createdAt" gorm:"type:timestamptz"`
	UpdatedAt time.Time      `json:"updatedAt" gorm:"type:timestamptz"`
	DeletedAt gorm.DeletedAt `json:"deletedAt"`
}

Model is recommended basic fields for every table

func (Model) HasChanged

func (m Model) HasChanged() bool

func (Model) IsDel

func (m Model) IsDel() bool

type ModelConstraint

type ModelConstraint interface {
	HasChanged() bool
	IsDel() bool
}

Directories

Path Synopsis
helper
page
Package page
Package page
sqlBuilder
Package sqlBuilder
Package sqlBuilder

Jump to

Keyboard shortcuts

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