Documentation ¶
Index ¶
- Variables
- func Decode(context *qor.Context, result interface{}, res Resourcer) error
- func DecodeToResource(res Resourcer, result interface{}, metaValues *MetaValues, ...) *processor
- type MetaValue
- type MetaValues
- type Metaor
- type Resource
- func (res *Resource) AddProcessor(fc func(interface{}, *MetaValues, *qor.Context) error)
- func (res *Resource) AddValidator(fc func(interface{}, *MetaValues, *qor.Context) error)
- func (res *Resource) CallDeleter(result interface{}, context *qor.Context) error
- func (res *Resource) CallFindMany(result interface{}, context *qor.Context) error
- func (res *Resource) CallFindOne(result interface{}, metaValues *MetaValues, context *qor.Context) error
- func (res *Resource) CallSaver(result interface{}, context *qor.Context) error
- func (res *Resource) GetMetas([]string) []Metaor
- func (res *Resource) GetResource() *Resource
- func (res *Resource) NewSlice() interface{}
- func (res *Resource) NewStruct() interface{}
- func (res *Resource) PrimaryDBName() (name string)
- func (res *Resource) PrimaryField() *gorm.Field
- func (res *Resource) PrimaryFieldName() (name string)
- type Resourcer
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrProcessorRecordNotFound = errors.New("resource: record not found") ErrProcessorSkipLeft = errors.New("resource: skip left") )
View Source
var DefaultDeleter = func(result interface{}, context *qor.Context) error { if !context.GetDB().First(result, context.ResourceID).RecordNotFound() { return context.GetDB().Delete(result).Error } else { return gorm.RecordNotFound } }
View Source
var DefaultFinder = func(result interface{}, metaValues *MetaValues, context *qor.Context) error { if metaValues == nil && context.ResourceID != "" { return context.GetDB().First(result, context.ResourceID).Error } return errors.New("failed to find") }
View Source
var DefaultSaver = func(result interface{}, context *qor.Context) error {
return context.GetDB().Save(result).Error
}
View Source
var DefaultSearcher = func(result interface{}, context *qor.Context) error {
return context.GetDB().Set("gorm:order_by_primary_key", "DESC").Find(result).Error
}
Functions ¶
func DecodeToResource ¶
func DecodeToResource(res Resourcer, result interface{}, metaValues *MetaValues, context *qor.Context) *processor
Types ¶
type MetaValue ¶
type MetaValue struct { Name string Value interface{} MetaValues *MetaValues Meta Metaor // contains filtered or unexported fields }
type MetaValues ¶
type MetaValues struct {
Values []*MetaValue
}
func ConvertFormToMetaValues ¶
func ConvertJSONToMetaValues ¶
func ConvertJSONToMetaValues(reader io.Reader, metaors []Metaor) (*MetaValues, error)
func (MetaValues) Get ¶
func (mvs MetaValues) Get(name string) *MetaValue
type Resource ¶
type Resource struct { Name string StructType string Value interface{} FindManyHandler func(interface{}, *qor.Context) error FindOneHandler func(interface{}, *MetaValues, *qor.Context) error Saver func(interface{}, *qor.Context) error Deleter func(interface{}, *qor.Context) error // contains filtered or unexported fields }
func (*Resource) AddProcessor ¶
func (res *Resource) AddProcessor(fc func(interface{}, *MetaValues, *qor.Context) error)
func (*Resource) AddValidator ¶
func (res *Resource) AddValidator(fc func(interface{}, *MetaValues, *qor.Context) error)
func (*Resource) CallDeleter ¶
func (*Resource) CallFindMany ¶
func (*Resource) CallFindOne ¶
func (res *Resource) CallFindOne(result interface{}, metaValues *MetaValues, context *qor.Context) error
func (*Resource) GetResource ¶
func (*Resource) PrimaryDBName ¶
func (*Resource) PrimaryField ¶
func (*Resource) PrimaryFieldName ¶
type Resourcer ¶
type Resourcer interface { GetResource() *Resource GetMetas([]string) []Metaor CallFindMany(interface{}, *qor.Context) error CallFindOne(interface{}, *MetaValues, *qor.Context) error CallSaver(interface{}, *qor.Context) error CallDeleter(interface{}, *qor.Context) error NewSlice() interface{} NewStruct() interface{} }
Click to show internal directories.
Click to hide internal directories.