Documentation ¶
Index ¶
- Variables
- func AppendToSliceAtFieldNum(modelObj IModel, fieldNum int, ele interface{})
- func FieldNameToColumn(modelObj IModel, fieldName string) (string, error)
- func FieldNameToJSONName(modelObj IModel, fieldName string) (string, error)
- func FindAllBetterRestPeggOrPegAssocIDs(modelObj interface{}, result *PeggedIDSearch) error
- func GetModelFieldTypeInModelIfValid(modelObj IModel, field string) (reflect.Type, error)
- func GetModelTableNameInModelIfValid(modelObj IModel, field string) (string, error)
- func GetModelTypeNameFromIModel(m IModel) string
- func GetTableNameFromIModel(imodel IModel) string
- func GetTableNameFromType(typ reflect.Type) string
- func IsFieldInModel(modelObj IModel, field string) bool
- func JSONKeysToFieldName(modelObj IModel, key string) (string, error)
- func SetSliceAtFieldNum(modelObj IModel, fieldNum int, ele interface{})
- func SetStructAtFieldNum(modelObj IModel, fieldNum int, ele interface{})
- func SetStructPtrAtFieldNum(modelObj IModel, fieldNum int, ele interface{})
- type BaseModel
- func (b *BaseModel) BeforeCreate(scope *gorm.Scope) error
- func (b *BaseModel) GetCreatedAt() *time.Time
- func (b *BaseModel) GetDeletedAt() *time.Time
- func (b *BaseModel) GetID() *datatype.UUID
- func (b *BaseModel) GetUpdatedAt() *time.Time
- func (b *BaseModel) SetID(id *datatype.UUID)
- func (b *BaseModel) Validate() error
- type FieldAsKey
- type FieldNotInModelError
- type FieldNumAndType
- type FieldType
- type IHasTableName
- type IModel
- type ModelAndIDs
- type PeggedIDSearch
- type Relation
Constants ¶
This section is empty.
Variables ¶
var ( Validate *validator.Validate Trans ut.Translator )
use a single instance , it caches struct info
Functions ¶
func AppendToSliceAtFieldNum ¶
func FieldNameToJSONName ¶
func FindAllBetterRestPeggOrPegAssocIDs ¶
func FindAllBetterRestPeggOrPegAssocIDs(modelObj interface{}, result *PeggedIDSearch) error
FindAllBetterRestPeggOrPegAssocIDs finds all Pegged or pegassoc ids, this is for OrgPartition which need pegged field only, pegassoc not yet tested. Many to many not handled at this point This is modified from markForDelete in gormfix and gormfixes modelObj is not mdl.IModel just because I don't need the dependency, may make it more generic later
func GetModelFieldTypeInModelIfValid ¶
Never returns the pointer value Since what we want is reflec.New() and it would be a pointer
func GetTableNameFromIModel ¶
GetTableNameFromIModel gets table name from an IModel
func GetTableNameFromType ¶
GetTableNameFromType get table name from the mdl reflect.type
func IsFieldInModel ¶
func JSONKeysToFieldName ¶
JSONKeyToColumnName transforms json name to column name if not found, return err By doing this we don't need mdl check?
func SetSliceAtFieldNum ¶
func SetStructAtFieldNum ¶
func SetStructPtrAtFieldNum ¶
Types ¶
type BaseModel ¶
type BaseModel struct { // For Postgres ID *datatype.UUID `gorm:"type:uuid;primary_key;" json:"id"` CreatedAt time.Time `sql:"index" json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt *time.Time `sql:"index" json:"deletedAt"` }
BaseModel is the base class domain mdl which has standard ID
func (*BaseModel) BeforeCreate ¶
BeforeCreate sets a UUID if no ID is set (this is Gorm's hookpoint)
func (*BaseModel) GetCreatedAt ¶
GetCreatedAt gets the time stamp the record is created
func (*BaseModel) GetDeletedAt ¶
GetUpdatedAt gets the time stamp the record is deleted (which we don't use)
func (*BaseModel) GetUpdatedAt ¶
GetUpdatedAt gets the time stamp the record is updated
type FieldAsKey ¶
type FieldNotInModelError ¶
type FieldNotInModelError struct {
Msg string
}
FieldNotInModelError is for GetModelFieldTypeIfValid. if field doesn't exist in the mdl, return this error We want to go ahead and skip it since this field may be other options that user can read in hookpoints
func (*FieldNotInModelError) Error ¶
func (r *FieldNotInModelError) Error() string
type FieldNumAndType ¶
type FieldNumAndType struct { FieldNum int TypeName string FieldName string ObjType reflect.Type IsSlice bool // Could be slice of pointer or not IsPtr bool IsStruct bool }
func GetPeggedFieldNumAndType ¶
func GetPeggedFieldNumAndType(modelObj IModel) []FieldNumAndType
type IHasTableName ¶
type IHasTableName interface {
TableName() string
}
IHasTableName we know if there is Gorm's defined custom TableName
type IModel ¶
type IModel interface { // The following two avoids having to use reflection to access ID GetID() *datatype.UUID SetID(id *datatype.UUID) GetCreatedAt() *time.Time GetUpdatedAt() *time.Time }
IModel is the interface for all domain mdl
type ModelAndIDs ¶
type ModelAndIDs struct { ModelObj IModel // this is just one or a new mdl we can look up // IDs is the parent ID who we want to query // IDs []interface{} // to send to Gorm need to be interface not *datatype.UUID IDs mapset.Set[string] // parent id ModelObjs []IModel // this is a storage when we've queried it }
type PeggedIDSearch ¶
type PeggedIDSearch struct { // There could be the same struct which exists in two places in the mdl // so we use FieldAsKey to store it, also tell us whether it was pointer or pointer to struct or slice // key is table name // tablename is the PARENT table name // tablename --> modelObj // ModelObjs map[string]reflect.Value // tablename -> FieldAsKey -> ids ToProcess map[string]map[FieldAsKey]*ModelAndIDs // those whose relationship with upper level is Peg }
func NewPeggedIDSearch ¶
func NewPeggedIDSearch() *PeggedIDSearch