Documentation ¶
Index ¶
- Variables
- func BaseCheckExists(model interface{}, ctx context.Context, query string, args ...interface{}) (exists bool, err error)
- func BaseCheckPKExists(model interface{}, ctx context.Context) (exists bool, err error)
- func GetPK(m interface{}) uint64
- func GetPKCol(m interface{}) bun.Ident
- func Middleware(next echo.HandlerFunc) echo.HandlerFunc
- func SetJWTConfig(config middleware.JWTConfig)
- func SetUserGetter(userGetter func(claims jwt.Claims) (u BaseFieldModel, err error))
- func UseDB(db *bun.DB)
- type BaseFieldModel
- type CtxQuery
- func (cq *CtxQuery) ApplySearch(searchCols bun.Safe)
- func (cq *CtxQuery) CheckExistsFromField(field interface{}) (exists bool, err error)
- func (cq *CtxQuery) CheckExistsFromPK(id uint64) (exists bool, err error)
- func (cq *CtxQuery) CheckFieldExists() (exists bool, err error)
- func (cq *CtxQuery) CheckPKExists() (exists bool, err error)
- func (cq *CtxQuery) ColAlias(column bun.Ident) bun.Ident
- func (cq *CtxQuery) DeleteFromPK() (err error)
- func (cq *CtxQuery) FromField() (err error)
- func (cq *CtxQuery) FromPK() (err error)
- func (cq *CtxQuery) FromParam() (err error)
- func (cq *CtxQuery) GetFromField(field interface{}) (err error)
- func (cq *CtxQuery) GetFromPK(id uint64) (err error)
- func (cq *CtxQuery) Insert() (err error)
- func (cq *CtxQuery) Q(q *bun.SelectQuery)
- func (cq *CtxQuery) SafeCol(column bun.Ident) bun.Safe
- func (cq *CtxQuery) Select()
- func (cq *CtxQuery) SetLimitOffset()
- func (cq *CtxQuery) SetPK() (err error)
- func (cq *CtxQuery) WhereParamToCol()
- type CustomRelI
- type DefaultJwtClaims
- type DefaultUser
- type RelApplier
- type RelApplyFunc
- type ReqCtx
Constants ¶
This section is empty.
Variables ¶
var ( DefaultRel = &RelApplier{UseDefault: true} IgnoredRel = &RelApplier{Ignore: true} )
var DB db
Functions ¶
func BaseCheckExists ¶
func BaseCheckPKExists ¶
func Middleware ¶
func Middleware(next echo.HandlerFunc) echo.HandlerFunc
Middleware provides echo middleware for `echo.Echo.Use()`
func SetJWTConfig ¶
func SetJWTConfig(config middleware.JWTConfig)
SetJWTConfig sets the primary JWT config from an echo.middleware.JWTConfig instance.
func SetUserGetter ¶
func SetUserGetter(userGetter func(claims jwt.Claims) (u BaseFieldModel, err error))
SetUserGetter takes a function to transform claims into a user as a `BaseFieldModel`.
Types ¶
type BaseFieldModel ¶
type BaseFieldModel interface { // GetSelectQuery must return a SelectQuery (excluding relations) suited for selecting the model based off of cq.Q. GetSelectQuery(cq *CtxQuery) *bun.SelectQuery // Insert must insert itself and the result or an error. Insert(rc *ReqCtx) (BaseFieldModel, error) // GetColumn must return the column name of the main field used to retrieve the model (not PK). GetColumn() bun.Ident // GetField must return the field used to retrieve the model (not PK). GetField() interface{} // GetParam must return the URL param name of the main field used to retrieve the model (not PK). GetParam() string }
BaseFieldModel provides an interface to models commonly referenced to help provide shortcuts.
type CtxQuery ¶
type CtxQuery struct { *bun.SelectQuery R *ReqCtx M BaseFieldModel JoinPrefix string TableAlias bun.Safe }
func (*CtxQuery) ApplySearch ¶
func (*CtxQuery) CheckExistsFromField ¶
func (*CtxQuery) CheckExistsFromPK ¶
func (*CtxQuery) CheckFieldExists ¶
func (*CtxQuery) CheckPKExists ¶
func (*CtxQuery) ColAlias ¶
ColAlias returns a query's column's alias for selection to bun, safe to use in joins.
func (*CtxQuery) DeleteFromPK ¶
func (*CtxQuery) GetFromField ¶
func (*CtxQuery) Select ¶
func (cq *CtxQuery) Select()
Select applies its model's GetSelectQuery and relations to itself.
func (*CtxQuery) SetLimitOffset ¶
func (cq *CtxQuery) SetLimitOffset()
SetLimitOffset sets a queries limit & offset from given URL parameters.
func (*CtxQuery) WhereParamToCol ¶
func (cq *CtxQuery) WhereParamToCol()
type CustomRelI ¶
type CustomRelI interface { BaseFieldModel GetCustomRel(rc *ReqCtx, rel *schema.Relation) *RelApplier }
CustomRelI provides functionality to customize relations to a BaseFieldModel. To disable a relation, return nil.
type DefaultJwtClaims ¶
type DefaultJwtClaims struct { User *DefaultUser `json:"user"` jwt.StandardClaims }
type DefaultUser ¶
type DefaultUser struct { bun.BaseModel `bun:"users,alias:user"` Username string `json:"username" bun:"username"` Id uint64 `json:"-" bun:"id,pk"` }
DefaultUser is the Default user for parsing JWT.
func (*DefaultUser) GetColumn ¶
func (*DefaultUser) GetColumn() bun.Ident
func (*DefaultUser) GetField ¶
func (m *DefaultUser) GetField() interface{}
func (*DefaultUser) GetParam ¶
func (*DefaultUser) GetParam() string
func (*DefaultUser) GetSelectQuery ¶
func (*DefaultUser) GetSelectQuery(cq *CtxQuery) *bun.SelectQuery
func (*DefaultUser) Insert ¶
func (b *DefaultUser) Insert(rc *ReqCtx) (m BaseFieldModel, err error)
type RelApplier ¶
type RelApplier struct { UseDefault bool Ignore bool ApplyFunc RelApplyFunc FollowModel BaseFieldModel }
RelApplier can customize how to handle a relation.
type RelApplyFunc ¶
type RelApplyFunc func(q *bun.SelectQuery) *bun.SelectQuery
type ReqCtx ¶
func NewCtx ¶
NewCtx creates a new ReqCtx instance from an echo and context Context object. Uses context.Background if ctx is nil.
func (*ReqCtx) AuthorInsert ¶
func (rc *ReqCtx) AuthorInsert(q *bun.InsertQuery) *bun.InsertQuery
AuthorInsert sets the user_id column to the request's user id on insert statements.
func (*ReqCtx) Query ¶
func (rc *ReqCtx) Query(m BaseFieldModel) *CtxQuery
func (*ReqCtx) Search ¶
func (rc *ReqCtx) Search(q *bun.SelectQuery, searchCols bun.Safe) *bun.SelectQuery