gormext

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name = "gorm"
)

Variables

This section is empty.

Functions

func ApplyCount

func ApplyCount[T Model](db *gorm.DB, q *query.Query) *gorm.DB

func ApplyQuery

func ApplyQuery[T Model](db *gorm.DB, q *query.Query) *gorm.DB

func Close

func Close(db *gorm.DB) error

func Connect

func Connect(conn Connection) (*gorm.DB, error)

func FromContext

func FromContext(ctx context.Context) *gorm.DB

func NewAutoPreload

func NewAutoPreload() gorm.Plugin

func TableName

func TableName(db *gorm.DB, model any) string

func ToContext

func ToContext(ctx context.Context, db *gorm.DB) context.Context

func Transaction

func Transaction(ctx context.Context, f func(ctx context.Context) error) (err error)

Types

type AutoPreload

type AutoPreload struct {
}

func (AutoPreload) Initialize

func (p AutoPreload) Initialize(db *gorm.DB) error

func (AutoPreload) Name

func (p AutoPreload) Name() string

type Connection

type Connection interface {
	DB() string
	DSN() string
}

type Crud

type Crud[M Model] interface {
	Create(ctx context.Context, model *M) error
	ReturnByPK(ctx context.Context, qs query.Encode, pk ...any) (*M, error)
	Update(ctx context.Context, model *M) error
	Save(ctx context.Context, model *M) error
	List(ctx context.Context, qs query.Encode) ([]*M, int64, error)
	DeleteByPK(ctx context.Context, pk ...any) error
	Delete(ctx context.Context, model *M) error
}

type CrudRepository

type CrudRepository[M Model] struct {
}

func NewCrudRepository

func NewCrudRepository[M Model]() *CrudRepository[M]

func (CrudRepository[M]) Create

func (r CrudRepository[M]) Create(ctx context.Context, model *M) error

func (CrudRepository[M]) Delete

func (r CrudRepository[M]) Delete(ctx context.Context, model *M) error

func (CrudRepository[M]) DeleteByPK

func (r CrudRepository[M]) DeleteByPK(ctx context.Context, pk ...any) error

func (CrudRepository[M]) List

func (r CrudRepository[M]) List(ctx context.Context, qe query.Encode) ([]*M, int64, error)

func (CrudRepository[M]) ReturnByPK

func (r CrudRepository[M]) ReturnByPK(ctx context.Context, qe query.Encode, pk ...any) (*M, error)

func (CrudRepository[M]) Save

func (r CrudRepository[M]) Save(ctx context.Context, model *M) error

func (CrudRepository[M]) Update

func (r CrudRepository[M]) Update(ctx context.Context, model *M) error

type IncrementalModel

type IncrementalModel struct {
	ID uint32 `gorm:"primaryKey"`
}

func (IncrementalModel) PrimaryKeys

func (m IncrementalModel) PrimaryKeys() []string

type Jsonb

type Jsonb struct {
	json.RawMessage
}

Jsonb Postgresql's JSONB data type

func (Jsonb) GormDBDataType

func (Jsonb) GormDBDataType(_å *gorm.DB, _ *schema.Field) string

func (*Jsonb) Scan

func (j *Jsonb) Scan(value any) error

Scan scan value into Jsonb

func (Jsonb) Value

func (j Jsonb) Value() (driver.Value, error)

Value get value of Jsonb

type Logger

type Logger struct{}

func NewLogger

func NewLogger() *Logger

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, s string, args ...any)

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, s string, args ...any)

func (*Logger) LogMode

func (*Logger) Trace

func (l *Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, s string, args ...any)

type Model

type Model interface {
	PrimaryKeys() []string
}

type NullTime

type NullTime struct {
	time.Time
	Valid bool
}

func (*NullTime) Scan

func (nt *NullTime) Scan(value interface{}) error

func (*NullTime) Set

func (nt *NullTime) Set(t *time.Time) NullTime

func (NullTime) Value

func (nt NullTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Point

type Point struct {
	Lng float64 `json:"lng" xml:"lng" yaml:"lng"`
	Lat float64 `json:"lat" xml:"lat" yaml:"lat"`
}

func (*Point) Scan

func (p *Point) Scan(val any) error

func (*Point) String

func (p *Point) String() string

func (Point) Value

func (p Point) Value() (driver.Value, error)
type Search interface {
	FullTextName() string
}

type Tabler

type Tabler interface {
	TableName() string
}

type UniversalModel

type UniversalModel struct {
	ID uuid.UUID `gorm:"primaryKey;default:uuid_generate_v4()"`
}

func (UniversalModel) PrimaryKeys

func (m UniversalModel) PrimaryKeys() []string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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