gormq

package
v0.0.0-...-a2ff9df Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTx

func CreateTx(hooks ...CreateTxHooks) func(crud.CreateQueryFunc) crud.CreateQueryFunc

func CtxInitQuery

func CtxInitQuery(ctx *gin.Context)

func CtxQuery

func CtxQuery(ctx *gin.Context) *gorm.DB

func CtxSetFactory

func CtxSetFactory(ctx *gin.Context, factory GormORMFactory)

func CtxSetQuery

func CtxSetQuery(ctx *gin.Context, db *gorm.DB)

func DestroyTx

func DestroyTx(hooks ...DestroyTxHooks) func(crud.DestroyQueryFunc) crud.DestroyQueryFunc

func FromDBConverter

func FromDBConverter[Model any]() func(map[string]any) (models.InternalValue, error)

FromDBConverter internally uses *sql.Scanner to convert a map[string]any to an InternalValue as GORM does this only for structs

func GormQueries

func GormQueries[Model any]() *crud.CRUD[Model]

GormQueries returns default queries providing basic CRUD functionality

func New

func New(ctx *gin.Context) *gorm.DB

func SQLScannerOrPassthrough

func SQLScannerOrPassthrough[Model any]() func(map[string]any, string, *gin.Context) (any, error)

func UpdateTx

func UpdateTx(hooks ...UpdateTxHooks) func(crud.UpdateQueryFunc) crud.UpdateQueryFunc

Types

type CreateTxHook

type CreateTxHook func(ctx *gin.Context, iv models.InternalValue, db *gorm.DB) (models.InternalValue, error)

type CreateTxHooks

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

func AfterCreate

func AfterCreate(hook CreateTxHook) CreateTxHooks

func BeforeCreate

func BeforeCreate(hook CreateTxHook) CreateTxHooks

type DestroyTxHook

type DestroyTxHook func(ctx *gin.Context, id any, db *gorm.DB) error

type DestroyTxHooks

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

func AfterDestroy

func AfterDestroy(hook DestroyTxHook) DestroyTxHooks

func BeforeDestroy

func BeforeDestroy(hook DestroyTxHook) DestroyTxHooks

type GormFilterFunc

type GormFilterFunc func(ctx *gin.Context, db *gorm.DB) *gorm.DB

type GormORMFactory

type GormORMFactory interface {
	Create(*gin.Context) *gorm.DB
}

func CtxGetFactory

func CtxGetFactory(ctx *gin.Context) GormORMFactory

func Dynamic

func Dynamic(dbFunc func(*gin.Context) *gorm.DB) GormORMFactory

Dynamic creates a GormORMFactory that provides a gorm.DB instance for each request, using the provided function. Make sure to create a new session for each query (if needed).

func Static

func Static(db *gorm.DB) GormORMFactory

Static creates a GormORMFactory that always returns the same gorm.DB instance, creating new sessions for each query.

type GormQueryDriver

type GormQueryDriver[Model any] struct {
	// contains filtered or unexported fields
}

func Gorm

func Gorm[Model any](factory GormORMFactory) *GormQueryDriver[Model]

func (GormQueryDriver[Model]) CRUD

func (g GormQueryDriver[Model]) CRUD() *crud.CRUD[Model]

func (GormQueryDriver[Model]) Filter

func (g GormQueryDriver[Model]) Filter() common.QueryMod

func (GormQueryDriver[Model]) Middleware

func (g GormQueryDriver[Model]) Middleware() []gin.HandlerFunc

func (GormQueryDriver[Model]) Order

func (g GormQueryDriver[Model]) Order() common.QueryMod

func (GormQueryDriver[Model]) Pagination

func (g GormQueryDriver[Model]) Pagination() common.Pagination

func (*GormQueryDriver[Model]) WithFilter

func (g *GormQueryDriver[Model]) WithFilter(filterFunc GormFilterFunc) *GormQueryDriver[Model]

func (*GormQueryDriver[Model]) WithOrderBy

func (g *GormQueryDriver[Model]) WithOrderBy(orderClause any) *GormQueryDriver[Model]

func (*GormQueryDriver[Model]) WithPagination

func (g *GormQueryDriver[Model]) WithPagination(pagination Pagination) *GormQueryDriver[Model]

type LimitOffsetPagination

type LimitOffsetPagination struct {
}

func (*LimitOffsetPagination) Apply

func (p *LimitOffsetPagination) Apply(c *gin.Context, db *gorm.DB) *gorm.DB

func (*LimitOffsetPagination) Format

func (p *LimitOffsetPagination) Format(c *gin.Context, entities []any) (any, error)

type NoPagination

type NoPagination struct{}

func (*NoPagination) Apply

func (p *NoPagination) Apply(_ *gin.Context, db *gorm.DB) *gorm.DB

func (*NoPagination) Format

func (p *NoPagination) Format(_ *gin.Context, entities []any) (any, error)

type Pagination

type Pagination interface {
	Apply(*gin.Context, *gorm.DB) *gorm.DB
	Format(*gin.Context, []any) (any, error)
}

type UpdateTxHook

type UpdateTxHook func(ctx *gin.Context, old models.InternalValue, new models.InternalValue, id any, db *gorm.DB) (models.InternalValue, error)

type UpdateTxHooks

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

func AfterUpdate

func AfterUpdate(hook UpdateTxHook) UpdateTxHooks

func BeforeUpdate

func BeforeUpdate(hook UpdateTxHook) UpdateTxHooks

Jump to

Keyboard shortcuts

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