Documentation
¶
Overview ¶
Package contenttype provides core interfaces and structs for content related model.
Author xc, Created on 2020-05-01 16:50 {COPYRIGHTS}
Index ¶
- Variables
- func AddVersionHook(hookPoint boil.HookPoint, versionHook VersionHook)
- func ContentToJson(content ContentTyper) (string, error)
- func GetLocations(contenttype string, cid int) (*[]Location, error)
- func IsUnderLocation(subLocation Location, location Location) bool
- func JsonToContent(contentJson string, content ContentTyper) error
- func MarchallToOutput(content ContentTyper) ([]byte, error)
- func NewList(contentType string) interface{}
- func NewQuery(mods ...qm.QueryMod) *queries.Query
- func Register(contentType string, register ContentTypeRegister)
- type ContentMap
- type ContentRelationList
- type ContentTypeRegister
- type ContentTyper
- type GetRelations
- type Location
- func (l *Location) CountLocations() int
- func (l *Location) Delete(ctx context.Context, transaction ...*sql.Tx) error
- func (c *Location) Field(name string) interface{}
- func (c *Location) GetLocationID() int
- func (l *Location) GetParentLocation() (*Location, error)
- func (c *Location) IdentifierList() []string
- func (l *Location) IsMainLocation() bool
- func (c *Location) Path() []int
- func (c *Location) Store(ctx context.Context, transaction ...*sql.Tx) error
- func (c *Location) TableName() string
- func (c *Location) ToDBValues() map[string]interface{}
- type M
- type Metadata
- type Relation
- type RelationList
- type User
- type Version
- type VersionHook
- type VersionSlice
Constants ¶
This section is empty.
Variables ¶
var ErrSyncFail = errors.New("contenttype: failed to synchronize data after insert")
ErrSyncFail occurs during insert when the record could not be retrieved in order to populate default value information. This usually happens when LastInsertId fails or there was a primary key configuration that was not resolvable.
var TableNames = struct { DMRelation string DMVersion string }{ DMRelation: "dm_relation", DMVersion: "dm_version", }
var VersionColumns = struct { ID string ContentType string ContentID string Version string Status string Author string Data string LocationID string Created string }{ ID: "id", ContentType: "content_type", ContentID: "content_id", Version: "version", Status: "status", Author: "author", Data: "data", LocationID: "location_id", Created: "created", }
var VersionRels = struct {
}{}
VersionRels is where relationship names are stored.
Functions ¶
func AddVersionHook ¶
func AddVersionHook(hookPoint boil.HookPoint, versionHook VersionHook)
AddVersionHook registers your hook function for all future operations.
func ContentToJson ¶
func ContentToJson(content ContentTyper) (string, error)
Content to json, used for internal content storing(eg. version data, draft data )
func IsUnderLocation ¶
func JsonToContent ¶
func JsonToContent(contentJson string, content ContentTyper) error
Json to Content, used for internal content recoving. (eg. versioning, draft)
func MarchallToOutput ¶
func MarchallToOutput(content ContentTyper) ([]byte, error)
func Register ¶
func Register(contentType string, register ContentTypeRegister)
Register a content type and store in global variable
Types ¶
type ContentMap ¶
type ContentMap map[string]interface{}
func ContentToMap ¶
func ContentToMap(content ContentTyper) (ContentMap, error)
Convert content to map
type ContentRelationList ¶
type ContentRelationList map[string]RelationList
ContentRelations as a struct which is linked into a content. The purpose is for binding & access.
func (*ContentRelationList) Scan ¶
func (relations *ContentRelationList) Scan(src interface{}) error
type ContentTypeRegister ¶
type ContentTypeRegister struct { New func() ContentTyper NewList func() interface{} ToList func(obj interface{}) []ContentTyper }
todo: use a better name. eg. ContentTypeMethod
type ContentTyper ¶
type ContentTyper interface { GetID() int GetName() string SetValue(identifier string, value interface{}) error Store(ctx context.Context, transaction ...*sql.Tx) error Delete(ctx context.Context, transaction ...*sql.Tx) error Value(identifier string) interface{} ContentType() string IdentifierList() []string GetLocation() *Location Definition(language ...string) definition.ContentType GetMetadata() *Metadata }
All the content type(eg. article, folder) will implement this interface.
func NewInstance ¶
func NewInstance(contentType string) ContentTyper
Create new content instance, eg. &Article{}
func ToList ¶
func ToList(contentType string, obj interface{}) []ContentTyper
Convert a *[]Article type(used for binding) to a slice of ContentTyper(use for more generic handling) todo: merge NewList with ToList
type GetRelations ¶
type GetRelations interface {
GetRelations() ContentRelationList
}
type Location ¶
type Location struct { ID int `boil:"id" json:"id" toml:"id" yaml:"id"` ParentID int `boil:"parent_id" json:"parent_id" toml:"parent_id" yaml:"parent_id"` MainID int `boil:"main_id" json:"main_id" toml:"main_id" yaml:"main_id"` IdentifierPath string `boil:"identifier_path" json:"identifier_path" toml:"identifier_path" yaml:"identifier_path"` Hierarchy string `boil:"hierarchy" json:"hierarchy" toml:"hierarchy" yaml:"hierarchy"` Depth int `boil:"depth" json:"depth" toml:"depth" yaml:"depth"` Contenttype string `boil:"content_type" json:"content_type" toml:"content_type" yaml:"content_type"` ContentID int `boil:"content_id" json:"content_id" toml:"content_id" yaml:"content_id"` IsHidden bool `boil:"is_hidden" json:"is_hidden" toml:"is_hidden" yaml:"is_hidden"` IsInvisible bool `boil:"is_invisible" json:"is_invisible" toml:"is_invisible" yaml:"is_invisible"` Priority int `boil:"priority" json:"priority" toml:"priority" yaml:"priority"` UID string `boil:"uid" json:"uid" toml:"uid" yaml:"uid"` Section string `boil:"section" json:"section" toml:"section" yaml:"section"` P string `boil:"p" json:"p" toml:"p" yaml:"p"` // contains filtered or unexported fields }
Location is an object representing the database table. Implement dm.contenttype.ContentTyper interface
func GetLocationByID ¶
func (*Location) CountLocations ¶
Count how many locations for the same content Note: the count is instant so not cached.
func (*Location) GetLocationID ¶
func (*Location) GetParentLocation ¶
Get parent id. no cache for now.
func (*Location) IdentifierList ¶
func (*Location) IsMainLocation ¶
If the location is main location
func (*Location) ToDBValues ¶
type M ¶
type M map[string]interface{}
M type is for providing columns and column values to UpdateAll.
type Metadata ¶
type Metadata struct { Contenttype string `boil:"_contenttype" json:"contenttype" toml:"contenttype" yaml:"contenttype"` Name string `boil:"_name" json:"name" toml:"name" yaml:"name"` Version int `boil:"_version" json:"version" toml:"version" yaml:"version"` Published time.Time `boil:"_published" json:"published" toml:"published" yaml:"published"` Modified time.Time `boil:"_modified" json:"modified" toml:"modified" yaml:"modified"` CUID string `boil:"_cuid" json:"cuid" toml:"cuid" yaml:"cuid"` Author int `boil:"_author" json:"author" toml:"author" yaml:"author"` AuthorName string `boil:"_author_name" json:"author_name" toml:"author_name" yaml:"author_name"` //Relations is used for binding all relationlist. See FinishBind to assign to different relationlist Relations ContentRelationList `boil:"_relations" json:"-" toml:"relations" yaml:"relations"` }
func (Metadata) ContentType ¶
func (Metadata) Definition ¶
func (c Metadata) Definition(language ...string) definition.ContentType
func (*Metadata) GetRelations ¶
func (c *Metadata) GetRelations() ContentRelationList
func (Metadata) IdentifierList ¶
IdentifierList return list of all field names
func (Metadata) ToDBValues ¶
Values return values for insert/update DB. todo: rename to ToDBValues()
type Relation ¶
type Relation struct { ID int `boil:"id" json:"-" toml:"id" yaml:"id"` ToContentID int `boil:"to_content_id" json:"-" toml:"to_content_id" yaml:"to_content_id"` ToType string `boil:"to_type" json:"-" toml:"to_type" yaml:"to_type"` FromContentID int `boil:"from_content_id" json:"from_content_id" toml:"from_content_id" yaml:"from_content_id"` FromType string `boil:"from_type" json:"from_type" toml:"from_type" yaml:"from_type"` FromLocation int `boil:"from_location" json:"-" toml:"from_location" yaml:"from_location"` Priority int `boil:"priority" json:"priority" toml:"priority" yaml:"priority"` Identifier string `boil:"identifier" json:"identifier" toml:"identifier" yaml:"identifier"` Description string `boil:"description" json:"description" toml:"description" yaml:"description"` Data string `boil:"data" json:"data" toml:"data" yaml:"data"` UID string `boil:"uid" json:"-" toml:"uid" yaml:"uid"` }
type RelationList ¶
type RelationList []Relation
A list of relation. Not used for bind so no Scan is not implemented
type User ¶
type User interface { ContentTyper ID() int Username() string Email() string }
User interface which is also a content type
type Version ¶
type Version struct { ID int `boil:"id" json:"id" toml:"id" yaml:"id"` ContentType string `boil:"content_type" json:"content_type" toml:"content_type" yaml:"content_type"` ContentID int `boil:"content_id" json:"content_id" toml:"content_id" yaml:"content_id"` Version int `boil:"version" json:"version" toml:"version" yaml:"version"` Status int8 `boil:"status" json:"status" toml:"status" yaml:"status"` Author int `boil:"author" json:"author" toml:"author" yaml:"author"` Data string `boil:"data" json:"data" toml:"data" yaml:"data"` LocationID int `boil:"location_id" json:"location_id" toml:"location_id" yaml:"location_id"` Created int `boil:"created" json:"created" toml:"created" yaml:"created"` R *versionR `boil:"-" json:"-" toml:"-" yaml:"-"` L versionL `boil:"-" json:"-" toml:"-" yaml:"-"` Location `boil:"dm_location,bind"` }
Version is an object representing the database table. Implement dm.contenttype.ContentTyper interface
func (*Version) Upsert ¶
func (o *Version) Upsert(ctx context.Context, exec boil.ContextExecutor, updateColumns, insertColumns boil.Columns) error
Upsert attempts an insert using an executor, and does an update or ignore on conflict. See boil.Columns documentation for how to properly use updateColumns and insertColumns.
type VersionHook ¶
VersionHook is the signature for custom Version hook methods
type VersionSlice ¶
type VersionSlice []*Version
VersionSlice is an alias for a slice of pointers to Version. This should generally be used opposed to []Version.