registry

package
v0.9.12 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ModelRegistry = make(map[string]*Reg)

ModelRegistry is model registry

View Source
var UserTyp reflect.Type

UserTyp is the model of the User table

Functions

func CreateBetterRESTTable

func CreateBetterRESTTable()

CreateBetterRESTTable registers models

func GetTableNameFromTypeString

func GetTableNameFromTypeString(typeString string) string

GetTableNameFromTypeString get table name from typeString

func NewFromTypeString

func NewFromTypeString(typeString string) models.IModel

NewFromTypeString instantiate a new models.IModel object from type registry

func NewOrgModelFromOrgResourceTypeString

func NewOrgModelFromOrgResourceTypeString(typeString string) models.IModel

NewOrgModelFromOrgResourceTypeString gets Organization object If you're a resource under hooked up by Organization

func NewOrgOwnershipModelFromOrgResourceTypeString

func NewOrgOwnershipModelFromOrgResourceTypeString(typeString string) models.IModel

NewOrgOwnershipModelFromOrgResourceTypeString gets the joining table from the resource's organization model to the user

func NewOwnershipModelFromOwnershipResourceTypeString

func NewOwnershipModelFromOwnershipResourceTypeString(typeString string) models.IModel

NewOwnershipModelFromOwnershipResourceTypeString returns the model object of the ownership table (the table that links from this resource represented by the type string to the user)

func NewSliceFromDBByType

func NewSliceFromDBByType(modelType reflect.Type, f func(interface{}, ...interface{}) *gorm.DB) ([]models.IModel, error)

NewSliceFromDBByType queries the database for an array of models based on modelType func(dest interface{}) *gorm.DB

func NewSliceFromDBByTypeString

func NewSliceFromDBByTypeString(typeString string, f func(interface{}, ...interface{}) *gorm.DB) ([]models.IModel, error)

NewSliceFromDBByTypeString queries the database for an array of models based on typeString func(dest interface{}) *gorm.DB

func NewSliceStructFromTypeString

func NewSliceStructFromTypeString(typeString string) []models.IModel

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][]models.IModel {

func OrgModelNameFromOrgResourceTypeString

func OrgModelNameFromOrgResourceTypeString(typeString string) string

OrgModelNameFromOrgResourceTypeString given org resource typeString, returns organization table name

func OrgModelTypeFromOrgResourceTypeString

func OrgModelTypeFromOrgResourceTypeString(typeString string) reflect.Type

------------------------- OrgModelTypeFromOrgResourceTypeString given org resource typeString returns the reflect type of the organization

func OrgOwnershipModelNameFromOrgResourceTypeString

func OrgOwnershipModelNameFromOrgResourceTypeString(typeString string) string

OrgOwnershipModelNameFromOrgResourceTypeString given org resource typeString, returns name of organization table's linking table (ownership table) to user

func OwnershipTableNameFromOwnershipResourceTypeString

func OwnershipTableNameFromOwnershipResourceTypeString(typeString string) string

OwnershipTableNameFromOwnershipResourceTypeString given ownership resource typeStirng returns name of ownership table to the user

Types

type BetterRESTTable

type BetterRESTTable struct {
	ID        *datatypes.UUID `gorm:"type:uuid;primary_key;" json:"id"`
	CreatedAt time.Time       `json:"createdAt" json:"createdAt"`
	UpdatedAt time.Time       `json:"updatedAt"`

	// Name is table name
	Name string `gorm:"unique_index:name"`
	// Version is table version
	Version string
}

BetterRESTTable store the information on all other models

type MapperType

type MapperType int

MapperType is the mapper type

const (
	// MapperTypeViaOwnership is for type which user owns something
	MapperTypeViaOwnership MapperType = iota

	// MapperTypeUser is user itself
	MapperTypeUser

	// MapperTypeViaOrganization is for type where an organization owns something
	MapperTypeViaOrganization

	// MapperTypeViaOrgPartition is for type where an organization owns something and it's in partitioned table
	MapperTypeViaOrgPartition

	// MapperTypeGlobal is for type where data is public to all
	MapperTypeGlobal

	// MapperTypeLinkTable is for table linking user and regular models
	MapperTypeLinkTable
)

type Reg

type Reg struct {
	Typ        reflect.Type
	TypVersion string // TypVersion is the Version of this model
	// CreateObj is by default the one passed in when calling RegModel*
	// It could be overriden with RegCustomCreate()
	CreateObj models.IModel

	// If type is link to user type, store type of ownership table (the one
	// that links to user)
	OwnershipType      reflect.Type
	OwnershipTableName *string
	// If custom ownership table is registered, store here
	OwnershipModelObjPtr models.IModel

	OrgTypeString string // If type has link to organization type, store organization typestring

	// CreateMethod can be defined with RegCustomCreate()
	CreateMethod func(db *gorm.DB) (*gorm.DB, error)

	GuardMethod func(who models.UserIDFetchable, info *hookhandler.EndPointInfo) *webrender.RetError

	BatchMethods string     // Batch endpoints, "CRUD" for create, batch read, batch update, batch delete
	IdvMethods   string     //  ID end points, "RUD" for read one, update one, and delete one
	Mapper       MapperType // Custmized mapper, default to datamapper.SharedOwnershipMapper

	// Begin deprecated
	BeforeCUPD func(bhpData models.BatchHookPointData, op models.CRUPDOp) error // no R since model doens't exist yet
	AfterCRUPD func(bhpData models.BatchHookPointData, op models.CRUPDOp) error

	AfterTransact func(bhpData models.BatchHookPointData, op models.CRUPDOp)

	AfterRead func(bhpData models.BatchHookPointData) error

	BeforeCreate func(bhpData models.BatchHookPointData) error
	AfterCreate  func(bhpData models.BatchHookPointData) error

	BeforeUpdate func(bhpData models.BatchHookPointData) error
	AfterUpdate  func(bhpData models.BatchHookPointData) error

	BeforePatchApply func(bhpData models.BatchHookPointData) error // This comes before patch is applied. Before "BeforePatch"
	BeforePatch      func(bhpData models.BatchHookPointData) error
	AfterPatch       func(bhpData models.BatchHookPointData) error

	BeforeDelete func(bhpData models.BatchHookPointData) error
	AfterDelete  func(bhpData models.BatchHookPointData) error

	BatchRenderer func(c *gin.Context, ms []models.IModel, bhpdata *models.BatchHookPointData, op models.CRUPDOp) bool

	// HandlerMap is the new method where we keep handlers
	// You can register any number of hookhandler to handle the rest process.
	// When each conncection is intantiated, the hookhandler remain in memory until the REST op is returned
	// If there are two hookhandler which handles the same method and the same hook, they will both be called.
	// The calling order is not guaranteed.
	HandlerMap *handlermap.HandlerMap

	RendererMethod func(c *gin.Context, data *hookhandler.Data, info *hookhandler.EndPointInfo) bool
}

Reg is a registry item

type RegOptions

type RegOptions struct {
	BatchMethods string // Batch endpoints, "CRUD" for create, batch read, batch update, batch delete
	IdvMethods   string //  ID end points, "RUD" for read one, update one, and delete one
	Mapper       MapperType
}

RegOptions is options when you want to add a model to registry

type Registrar

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

Registrar has registration methods for models

func For

func For(typeString string) *Registrar

For set the current registering typeString

func NewRegistrar

func NewRegistrar(typeString string) *Registrar

func (*Registrar) BatchAfterTransactHook

func (r *Registrar) BatchAfterTransactHook(
	hook func(bhpData models.BatchHookPointData, op models.CRUPDOp)) *Registrar

BatchCRUPDHooks adds hookpoints which are called before CUPD (no read) and after batch CRUPD. Either one can be left as nil

func (*Registrar) BatchCRUPDHooks

func (r *Registrar) BatchCRUPDHooks(
	before func(bhpData models.BatchHookPointData, op models.CRUPDOp) error,
	after func(bhpData models.BatchHookPointData, op models.CRUPDOp) error) *Registrar

BatchCRUPDHooks adds hookpoints which are called before CUPD (no read) and after batch CRUPD. Either one can be left as nil

func (*Registrar) BatchCreateHooks

func (r *Registrar) BatchCreateHooks(
	before func(bhpData models.BatchHookPointData) error,
	after func(bhpData models.BatchHookPointData) error) *Registrar

BatchCreateHooks adds hookpoints which are called before and after batch update. Either one can be left as nil

func (*Registrar) BatchDeleteHooks

func (r *Registrar) BatchDeleteHooks(
	before func(bhpData models.BatchHookPointData) error,
	after func(bhpData models.BatchHookPointData) error) *Registrar

BatchDeleteHooks adds hookpoints which are called before and after batch delete. Either one can be left as nil

func (*Registrar) BatchPatchHooks

func (r *Registrar) BatchPatchHooks(
	beforeApply func(bhpData models.BatchHookPointData) error,
	before func(bhpData models.BatchHookPointData) error,
	after func(bhpData models.BatchHookPointData) error) *Registrar

BatchPatchHooks adds hookpoints which are called before and after batch update. Either one can be left as nil

func (*Registrar) BatchReadHooks

func (r *Registrar) BatchReadHooks(after func(bhpData models.BatchHookPointData) error) *Registrar

BatchReadHooks adds hookpoints which are called after and read, can be left as nil

func (*Registrar) BatchRenderer

func (r *Registrar) BatchRenderer(renderer func(c *gin.Context, ms []models.IModel, bhpdata *models.BatchHookPointData, op models.CRUPDOp) bool) *Registrar

Deprecated BatchRenderer register custom batch renderer (do your own output, not necessarily JSON)

func (*Registrar) BatchUpdateHooks

func (r *Registrar) BatchUpdateHooks(
	before func(bhpData models.BatchHookPointData) error,
	after func(bhpData models.BatchHookPointData) error) *Registrar

BatchUpdateHooks adds hookpoints which are called before and after batch update. Either one can be left as nil

func (*Registrar) CustomCreate

func (r *Registrar) CustomCreate(modelObj models.IModel, f func(db *gorm.DB) (*gorm.DB, error)) *Registrar

CustomCreate register custom create table funtion

func (*Registrar) Guard

Guard register guard function

func (*Registrar) Hook added in v0.9.5

func (r *Registrar) Hook(hdlr hookhandler.IHookhandler, method string, args ...interface{}) *Registrar

Hook adds the handler (contains one or more hooks) to be instantiate when a REST op occurs. If any hookhandler exists, old model-based hookpoints and batch hookpoints are not called

func (*Registrar) Model

func (r *Registrar) Model(modelObj models.IModel) *Registrar

Model adds a New function for an models.IModel (convenient function of RegModelWithOption)

func (*Registrar) ModelWithOption

func (r *Registrar) ModelWithOption(modelObj models.IModel, options RegOptions) *Registrar

ModelWithOption adds a New function for an models.IModel

func (*Registrar) Renderer

func (r *Registrar) Renderer(renderer func(c *gin.Context, data *hookhandler.Data, info *hookhandler.EndPointInfo) bool) *Registrar

Renderer is called for both cardinalities when registered

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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