gormext

package
v1.3.16 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name = "gorm"
)

Variables

This section is empty.

Functions

func ApplyCount

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

func ApplyQuery

func ApplyQuery[T any](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 DIMiddleware added in v1.3.0

func DIMiddleware(db *gorm.DB) mux.MiddlewareFunc

func NewLogger

func NewLogger() *logger

func TableName

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

func Transaction added in v1.2.1

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

func UnaryDIInterceptor

func UnaryDIInterceptor(db *gorm.DB) grpc.UnaryServerInterceptor

Types

type Connection

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

type Crud

type Crud[M Identity[K], K any] interface {
	Create(ctx context.Context, model *M) error
	ReturnByID(ctx context.Context, id K, qs query.Encode) (*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)
	DeleteByID(ctx context.Context, id K) error
	Delete(ctx context.Context, model *M) error
}

type CrudRepository

type CrudRepository[M Identity[K], K any] struct {
}

func NewCrudRepository

func NewCrudRepository[M Identity[K], K any]() *CrudRepository[M, K]

func (CrudRepository[M, K]) Create

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

func (CrudRepository[M, K]) DB

func (r CrudRepository[M, K]) DB(ctx context.Context) *gorm.DB

func (CrudRepository[M, K]) Delete

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

func (CrudRepository[M, K]) DeleteByID

func (r CrudRepository[M, K]) DeleteByID(ctx context.Context, id K) error

func (CrudRepository[M, K]) List

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

func (CrudRepository[M, K]) ReturnByID

func (r CrudRepository[M, K]) ReturnByID(ctx context.Context, id K, qe query.Encode) (*M, error)

func (CrudRepository[M, K]) Save

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

func (CrudRepository[M, K]) Update

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

type Identity

type Identity[T any] interface {
	GetID() T
}

type IncrementalModel

type IncrementalModel struct {
	ID uint32
}

func (IncrementalModel) GetID

func (m IncrementalModel) GetID() uint32

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 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:"default:uuid_generate_v4()"`
}

func (UniversalModel) GetID

func (m UniversalModel) GetID() uuid.UUID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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