contenttype

package
v0.1.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 21 Imported by: 1

Documentation

Overview

Package contenttype provides core interfaces and structs for content related model.

Author xc, Created on 2020-05-01 16:50 {COPYRIGHTS}

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
var TableNames = struct {
	DMRelation string
	DMVersion  string
}{
	DMRelation: "dm_relation",
	DMVersion:  "dm_version",
}
View Source
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",
}
View Source
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 GetLocations

func GetLocations(contenttype string, cid int) (*[]Location, error)

func IsUnderLocation

func IsUnderLocation(subLocation Location, location Location) bool

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 NewList

func NewList(contentType string) interface{}

Create new list.eg &[]Article{}

func NewQuery

func NewQuery(mods ...qm.QueryMod) *queries.Query

NewQuery initializes a new Query using the passed in QueryMods

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 GetLocationByID(locationID int) (*Location, error)

func (*Location) CountLocations

func (l *Location) CountLocations() int

Count how many locations for the same content Note: the count is instant so not cached.

func (*Location) Delete

func (l *Location) Delete(ctx context.Context, transaction ...*sql.Tx) error

Delete location only

func (*Location) Field

func (c *Location) Field(name string) interface{}

func (*Location) GetLocationID

func (c *Location) GetLocationID() int

func (*Location) GetParentLocation

func (l *Location) GetParentLocation() (*Location, error)

Get parent id. no cache for now.

func (*Location) IdentifierList

func (c *Location) IdentifierList() []string

func (*Location) IsMainLocation

func (l *Location) IsMainLocation() bool

If the location is main location

func (*Location) Path

func (c *Location) Path() []int

Get path array from hierarchy. eg[1, 2]

func (*Location) Store

func (c *Location) Store(ctx context.Context, transaction ...*sql.Tx) error

func (*Location) TableName

func (c *Location) TableName() string

func (*Location) ToDBValues

func (c *Location) ToDBValues() map[string]interface{}

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 (c Metadata) ContentType() string

func (Metadata) Definition

func (c Metadata) Definition(language ...string) definition.ContentType

func (Metadata) GetName

func (c Metadata) GetName() string

func (*Metadata) GetRelations

func (c *Metadata) GetRelations() ContentRelationList

func (Metadata) IdentifierList

func (c Metadata) IdentifierList() []string

IdentifierList return list of all field names

func (Metadata) ToDBValues

func (c Metadata) ToDBValues() map[string]interface{}

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) Field

func (c *Version) Field(name string) interface{}

func (Version) Store

func (c Version) Store(ctx context.Context, transaction ...*sql.Tx) error

func (*Version) TableName

func (c *Version) TableName() string

func (*Version) ToMap

func (c *Version) ToMap() map[string]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

type VersionHook func(context.Context, boil.ContextExecutor, *Version) error

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.

Jump to

Keyboard shortcuts

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