Documentation ¶
Index ¶
- Constants
- Variables
- func AddBatchDeleteBeforeAndAfterHookPoints(typeString string, ...)
- func AddBatchInsertBeforeAndAfterHookPoints(typeString string, ...)
- func AddBatchReadAfterHookPoint(typeString string, ...)
- func AddBatchUpdateBeforeAndAfterHookPoints(typeString string, ...)
- func AddModelRegistry(typeString string, typ reflect.Type)
- func AddModelRegistryWithOptions(typeString string, typ reflect.Type, options ModelRegistryOptions)
- func AddOwnerToModelRegistry(typeString string, typ reflect.Type)
- func AddUserToModelRegistry(typeString string, typ reflect.Type)
- func GetJoinTableName(modelObj IHasOwnershipLink) string
- func GetOrganizationTableName(modelObj IHasOrganizationLink) string
- func GetTableNameFromIModel(model IModel) string
- func GetTableNameFromType(typ reflect.Type) string
- func GetTableNameFromTypeString(typeString string) string
- type BaseModel
- type BatchHookCargo
- type Client
- type IAfterDelete
- type IAfterInsert
- type IAfterLogin
- type IAfterPatch
- type IAfterRead
- type IAfterUpdate
- type IBeforeDelete
- type IBeforeInsert
- type IBeforeLogin
- type IBeforePatch
- type IBeforeUpdate
- type IDoRealDelete
- type IGuardAPIEntry
- type IHasOrganizationLink
- type IHasOwnershipLink
- type IHasTableName
- type IModel
- func NewFromTypeString(typeString string) IModel
- func NewSliceFromDBByType(modelType reflect.Type, f func(interface{}, ...interface{}) *gorm.DB) ([]IModel, error)
- func NewSliceFromDBByTypeString(typeString string, f func(interface{}, ...interface{}) *gorm.DB) ([]IModel, error)
- func NewSliceStructFromTypeString(typeString string) []IModel
- type IOwnership
- type IValidate
- type MapperType
- type ModelCargo
- type ModelRegistryOptions
- type OwnershipModelBase
- func (o *OwnershipModelBase) GetModelID() *datatypes.UUID
- func (o *OwnershipModelBase) GetRole() UserRole
- func (o *OwnershipModelBase) GetUserID() *datatypes.UUID
- func (o *OwnershipModelBase) SetModelID(id *datatypes.UUID)
- func (o *OwnershipModelBase) SetRole(r UserRole)
- func (o *OwnershipModelBase) SetUserID(id *datatypes.UUID)
- type Reg
- type UserRole
Constants ¶
const ( // MapperTypeViaOwnership is for type which user owns something MapperTypeViaOwnership = 0 // MapperTypeViaOrganization is for type where an organization owns something MapperTypeViaOrganization = 1 // MapperTypeGlobal is for type where data is public to all MapperTypeGlobal = 2 )
Variables ¶
var ModelRegistry = make(map[string]*Reg)
ModelRegistry is model registry
var OwnerTyp reflect.Type
OwnerTyp is the model of the Owner table
var UserTyp reflect.Type
UserTyp is the model of the User table
var (
Validate *validator.Validate
)
use a single instance , it caches struct info
Functions ¶
func AddBatchDeleteBeforeAndAfterHookPoints ¶
func AddBatchDeleteBeforeAndAfterHookPoints(typeString string, before func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error, after func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error)
AddBatchDeleteBeforeAndAfterHookPoints adds hookpoints which are called before and after batch delete. Either one can be left as nil
func AddBatchInsertBeforeAndAfterHookPoints ¶ added in v0.1.24
func AddBatchInsertBeforeAndAfterHookPoints(typeString string, before func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error, after func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error)
AddBatchInsertBeforeAndAfterHookPoints adds hookpoints which are called before and after batch update. Either one can be left as nil
func AddBatchReadAfterHookPoint ¶ added in v0.1.18
func AddBatchReadAfterHookPoint(typeString string, after func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, roles []UserRole) error)
AddBatchReadAfterHookPoint adds hookpoints which are called after and read, can be left as nil
func AddBatchUpdateBeforeAndAfterHookPoints ¶
func AddBatchUpdateBeforeAndAfterHookPoints(typeString string, before func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error, after func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error)
AddBatchUpdateBeforeAndAfterHookPoints adds hookpoints which are called before and after batch update. Either one can be left as nil
func AddModelRegistry ¶
AddModelRegistry adds a New function for an IModel
func AddModelRegistryWithOptions ¶ added in v0.1.14
func AddModelRegistryWithOptions(typeString string, typ reflect.Type, options ModelRegistryOptions)
AddModelRegistryWithOptions adds a New function for an IModel
func AddOwnerToModelRegistry ¶ added in v0.1.8
AddOwnerToModelRegistry adds a New function for an owner
func AddUserToModelRegistry ¶ added in v0.1.3
AddUserToModelRegistry adds a New function for a user
func GetJoinTableName ¶ added in v0.1.34
func GetJoinTableName(modelObj IHasOwnershipLink) string
GetJoinTableName if comforms to IHasOwnershipLink
func GetOrganizationTableName ¶ added in v0.1.34
func GetOrganizationTableName(modelObj IHasOrganizationLink) string
GetOrganizationTableName if comforms to IHasOrganizationLink
func GetTableNameFromIModel ¶ added in v0.1.20
GetTableNameFromIModel gets table name from an IModel
func GetTableNameFromType ¶ added in v0.1.39
GetTableNameFromType get table name from the model reflect.type
func GetTableNameFromTypeString ¶ added in v0.1.39
GetTableNameFromTypeString get table name from typeString
Types ¶
type BaseModel ¶
type BaseModel struct { // For Postgres ID *datatypes.UUID `gorm:"type:uuid;primary_key;" json:"id"` CreatedAt time.Time `sql:"index" json:"createdAt"` UpdatedAt time.Time DeletedAt *time.Time `sql:"index"` }
BaseModel is the base class domain model which has standard ID
func (*BaseModel) BeforeCreate ¶
BeforeCreate sets a UUID if no ID is set (this is Gorm's hookpoint)
type BatchHookCargo ¶
type BatchHookCargo struct {
Payload interface{}
}
BatchHookCargo is payload between batch update and batch delete hookpoints
type Client ¶
type Client struct { gorm.Model // Includes ID, CreatedAt, UpdatedAt, DeletedAt Name string Secret string `gorm:"not null" json:"-"` RedirectURI string // TODO: RedirectURI can be multiples }
Client is the program that makes request to the API So iOS would be one client, android would be another Any website making API request would have its own client ID This needs to be inserted into db beforehand. So we can validate the app making the request. Any such app has the permission to create the user
type IAfterDelete ¶
type IAfterDelete interface {
AfterDeleteDB(db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *ModelCargo) error
}
IAfterDelete supports method to be called after data is deleted from the database
type IAfterInsert ¶
type IAfterInsert interface {
AfterInsertDB(db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *ModelCargo) error
}
IAfterInsert supports method to be called after data is inserted (created) into the database
type IAfterLogin ¶ added in v0.1.47
type IAfterLogin interface {
AfterLogin(db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *ModelCargo, payload map[string]interface{}) (map[string]interface{}, error)
}
IAfterLogin has a function that is a hookpoint for actions after login but before marshalling
type IAfterPatch ¶
type IAfterPatch interface {
AfterPatchDB(db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *ModelCargo) error
}
IAfterPatch supports method to be called before data is patched in the database
type IAfterRead ¶ added in v0.1.18
type IAfterRead interface {
AfterReadDB(db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, role *UserRole) error
}
IAfterRead supports method to be called after data is read from the database
type IAfterUpdate ¶
type IAfterUpdate interface {
AfterUpdateDB(db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *ModelCargo) error
}
IAfterUpdate supports method to be called after data is updated in the database
type IBeforeDelete ¶
type IBeforeDelete interface {
BeforeDeleteDB(db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *ModelCargo) error
}
IBeforeDelete supports method to be called before data is deleted from the database
type IBeforeInsert ¶
type IBeforeInsert interface {
BeforeInsertDB(db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *ModelCargo) error
}
IBeforeInsert supports method to be called before data is inserted (created) into the database
type IBeforeLogin ¶ added in v0.1.47
type IBeforeLogin interface {
BeforeLogin(db *gorm.DB, scope *string, typeString string, cargo *ModelCargo) error
}
IBeforeLogin has a function that is a hookpoint for actions after login but before marshalling
type IBeforePatch ¶
type IBeforePatch interface {
BeforePatchDB(db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *ModelCargo) error
}
IBeforePatch supports method to be called before data is patched in the database
type IBeforeUpdate ¶
type IBeforeUpdate interface {
BeforeUpdateDB(db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *ModelCargo) error
}
IBeforeUpdate supports method to be called before data is updated in the database
type IDoRealDelete ¶ added in v0.1.4
type IDoRealDelete interface {
DoRealDelete() bool
}
IDoRealDelete is an interface to customize specification for real db delete
type IGuardAPIEntry ¶ added in v0.1.25
IGuardAPIEntry supports method which guard access to API based on scope
type IHasOrganizationLink ¶ added in v0.1.28
type IHasOrganizationLink interface { OrganizationType() reflect.Type GetOrganizationID() *datatypes.UUID GetOrganizationIDFieldName() string }
IHasOrganizationLink has a function that returns the organization table usable for OrganizationMapper
type IHasOwnershipLink ¶ added in v0.1.28
IHasOwnershipLink has a function that returns the ownership table usable for OwnershipMapper
type IHasTableName ¶ added in v0.1.18
type IHasTableName interface {
TableName() string
}
IHasTableName we know if there is Gorm's defined custom TableName
type IModel ¶
type IModel interface { Permissions(r UserRole, scope *string) jsontransform.JSONFields // The following two avoids having to use reflection to access ID GetID() *datatypes.UUID SetID(id *datatypes.UUID) }
IModel is the interface for all domain models
func NewFromTypeString ¶
NewFromTypeString instantiate a new IModel object from type registry
func NewSliceFromDBByType ¶ added in v0.1.28
func NewSliceFromDBByType(modelType reflect.Type, f func(interface{}, ...interface{}) *gorm.DB) ([]IModel, error)
NewSliceFromDBByType queries the database for an array of models based on modelType func(dest interface{}) *gorm.DB
func NewSliceFromDBByTypeString ¶ added in v0.1.28
func NewSliceFromDBByTypeString(typeString string, f func(interface{}, ...interface{}) *gorm.DB) ([]IModel, error)
NewSliceFromDBByTypeString queries the database for an array of models based on typeString func(dest interface{}) *gorm.DB
func NewSliceStructFromTypeString ¶
NewSliceStructFromTypeString : return something originally like this obj := make(map[string][]Room) obj["content"] = make([]Room, 0, 0) https://stackoverflow.com/questions/50233285/create-a-map-in-go-using-reflection func NewSliceStructFromTypeString(typeString string) map[string][]IModel {
type IOwnership ¶ added in v0.1.18
type IOwnership interface { GetRole() UserRole SetRole(UserRole) GetUserID() *datatypes.UUID SetUserID(*datatypes.UUID) GetModelID() *datatypes.UUID SetModelID(*datatypes.UUID) }
IOwnership is what OwnershipModelBase tables should satisfy.
type ModelCargo ¶
type ModelCargo struct {
Payload interface{}
}
ModelCargo is payload between hookpoints
type ModelRegistryOptions ¶ added in v0.1.28
type ModelRegistryOptions struct { BatchEndpoints string // Batch endpoints, "CRUD" for create, batch read, batch update, batch delete IDEndPoints string // ID end points, "RUD" for read one, update one, and delete one Mapper MapperType }
ModelRegistryOptions is options when you want to add a model to registry
type OwnershipModelBase ¶ added in v0.1.3
type OwnershipModelBase struct { gorm.Model // uses standard int id (cuz I started with it and it works) UserID *datatypes.UUID ModelID *datatypes.UUID Role UserRole // an int }
OwnershipModelBase has a role
func (*OwnershipModelBase) GetModelID ¶ added in v0.1.18
func (o *OwnershipModelBase) GetModelID() *datatypes.UUID
GetModelID gets the id of the model, comforms to IOwnership
func (*OwnershipModelBase) GetRole ¶ added in v0.1.3
func (o *OwnershipModelBase) GetRole() UserRole
GetRole gets the role field of the model, comforms to IOwnership
func (*OwnershipModelBase) GetUserID ¶ added in v0.1.18
func (o *OwnershipModelBase) GetUserID() *datatypes.UUID
GetUserID gets the user id of the model, comforms to IOwnership
func (*OwnershipModelBase) SetModelID ¶ added in v0.1.18
func (o *OwnershipModelBase) SetModelID(id *datatypes.UUID)
SetModelID sets the id of the model, comforms to IOwnership
func (*OwnershipModelBase) SetRole ¶ added in v0.1.3
func (o *OwnershipModelBase) SetRole(r UserRole)
SetRole sets the role field of the model, comforms to IOwnership
func (*OwnershipModelBase) SetUserID ¶ added in v0.1.18
func (o *OwnershipModelBase) SetUserID(id *datatypes.UUID)
SetUserID sets the user id of the model, comforms to IOwnership
type Reg ¶
type Reg struct { Typ reflect.Type BatchEndpoints string // Batch endpoints, "CRUD" for create, batch read, batch update, batch delete IDEndPoints string // ID end points, "RUD" for read one, update one, and delete one Mapper MapperType // Custmized mapper, default to datamapper.SharedOwnershipMapper AfterRead func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, roles []UserRole) error BeforeInsert func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error AfterInsert func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error BeforeUpdate func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error AfterUpdate func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error BeforeDelete func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error AfterDelete func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, scope *string, typeString string, cargo *BatchHookCargo) error }
Reg is a registry item