model

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KnowledgeTypeNote knowledge type of note
	KnowledgeTypeNote = "note"
	// KnowledgeTypeDoc knowledge type of document
	KnowledgeTypeDoc = "doc"
)
View Source
const (
	// PostTypeArticle post type of article
	PostTypeArticle = "article"
	// PostTypePage post type of page
	PostTypePage = "page"
	// PostStatusPublish post status of published post
	PostStatusPublish = "publish"
	// PostStatusDraft post status of draft post
	PostStatusDraft = "draft"
	// PostStatusDeleted post status of deleted post
	PostStatusDeleted = "deleted"
)
View Source
const DefaultUnCategorizedID = 1

DefaultUnCategorizedID the default category's ID

View Source
const KnowledgeItemContentStatusCommon = 0

KnowledgeItemContentStatusCommon knowledge item content not current version

View Source
const KnowledgeItemContentStatusCurrent = 1

KnowledgeItemContentStatusCurrent knowledge item content current(published) version

View Source
const ResourceTypePicture = "picture"

ResourceTypePicture resource type of picture

View Source
const StatusNormal = 1

StatusNormal normal status value

View Source
const UsageCover = "cover"

UsageCover usage for cover

View Source
const UsageDefault = "common"

UsageDefault default usage

Variables

This section is empty.

Functions

func CheckTaxonomyNameExist

func CheckTaxonomyNameExist(db *gorm.DB, name, taxonomy string) bool

TaxonomyCheckNameExist check the taxonomy name if is already exist

Types

type Knowledge added in v0.4.0

type Knowledge struct {
	Model

	Name        string       `gorm:"column:name;not null"`
	Slug        string       `gorm:"column:slug;not null"`
	Type        string       `gorm:"column:type;not null"`
	Description string       `gorm:"column:description;not null"`
	CoverImage  uint64       `gorm:"column:cover_image;not null;default:0"`
	Status      uint8        `gorm:"column:status;not null;default:1"`
	LastUpdated sql.NullTime `gorm:"column:last_updated;default:null"`
}

Knowledge the definition of knowledge base model Note: because of the cover image will be uploaded first by a api, here do not consider to use a association mode

func (*Knowledge) Create added in v0.4.0

func (k *Knowledge) Create(db *gorm.DB) error

Create creates a new knowledge base

func (*Knowledge) GetByID added in v0.4.0

func (k *Knowledge) GetByID(db *gorm.DB) error

GetByID get knowledge base by ID

func (*Knowledge) Save added in v0.4.0

func (k *Knowledge) Save(db *gorm.DB) error

Save save knowledge base info

func (*Knowledge) TableName added in v0.4.0

func (k *Knowledge) TableName() string

TableName is the Knowledge table name in db

type KnowledgeItem added in v0.4.0

type KnowledgeItem struct {
	Model

	KnowledgeID    uint64       `gorm:"column:knowledge_id;not null"`
	Symbol         uint64       `gorm:"column:symbol;not null"`
	UserID         uint64       `gorm:"column:user_id;not null"`
	Title          string       `gorm:"column:title;not null"`
	ContentVersion uint64       `gorm:"column:content_version;not null"`
	ParentID       uint64       `gorm:"column:parent_id;not null;default:0"`
	Level          uint64       `gorm:"column:level;not null;default:0"`
	Index          int64        `gorm:"column:index;not null;default:0"`
	CommentCount   uint64       `gorm:"column:comment_count;not null;default:0"`
	ViewCount      uint64       `gorm:"column:view_count;not null;default:0"`
	LastPublished  sql.NullTime `gorm:"column:last_published;default:null"`

	ItemContents []KnowledgeItemContent `gorm:"foreignKey:KnowledgeItemID"`
}

func (*KnowledgeItem) Create added in v0.4.0

func (ki *KnowledgeItem) Create(db *gorm.DB) error

Create create a new knowledge item

func (*KnowledgeItem) Delete added in v0.4.0

func (ki *KnowledgeItem) Delete(db *gorm.DB) error

Delete delete the knowledge item by id

func (*KnowledgeItem) Get added in v0.4.0

func (ki *KnowledgeItem) Get(db *gorm.DB, where string, whereArgs []interface{}) ([]*KnowledgeItem, int64, error)

Get get all by condition

func (*KnowledgeItem) GetAll added in v0.4.0

func (ki *KnowledgeItem) GetAll(db *gorm.DB) ([]*KnowledgeItem, error)

GetAll get all knowledge items by knowledge id

func (*KnowledgeItem) GetByID added in v0.4.0

func (ki *KnowledgeItem) GetByID(db *gorm.DB) error

GetByID get knowledge item by ID

func (*KnowledgeItem) GetItemContent added in v0.4.0

func (ki *KnowledgeItem) GetItemContent(db *gorm.DB, where string, order string) ([]*KnowledgeItemContent, error)

GetLastContent get item contents

func (*KnowledgeItem) GetLargeIndexInLevel added in v0.4.0

func (ki *KnowledgeItem) GetLargeIndexInLevel(db *gorm.DB) (uint64, error)

GetLargeIndexInLevel get the largest index value in the same level

func (*KnowledgeItem) Save added in v0.4.0

func (ki *KnowledgeItem) Save(db *gorm.DB) error

Save update knowledge item

func (*KnowledgeItem) TableName added in v0.4.0

func (ki *KnowledgeItem) TableName() string

TableName is the knowledge item table name in db

type KnowledgeItemContent added in v0.4.0

type KnowledgeItemContent struct {
	ID              uint64    `gorm:"primaryKey;autoIncrement;column:id"`
	KnowledgeItemID uint64    `gorm:"column:knowledge_item_id;not null"`
	Version         uint64    `gorm:"column:version;not null"`
	Status          uint8     `gorm:"column:status;not null;default:0"`
	Content         string    `gorm:"column:content;not null"`
	UpdatedAt       time.Time `gorm:"column:updated_time;not null"`
}

func (*KnowledgeItemContent) Create added in v0.4.0

func (kic *KnowledgeItemContent) Create(db *gorm.DB) error

Create save the new version knowledge item content

func (*KnowledgeItemContent) GetByVersion added in v0.4.0

func (kic *KnowledgeItemContent) GetByVersion(db *gorm.DB) (*KnowledgeItemContent, error)

GetByVersion get knowledge item by version

func (*KnowledgeItemContent) Save added in v0.4.0

func (kic *KnowledgeItemContent) Save(db *gorm.DB) error

Save update knowledge item content

func (*KnowledgeItemContent) TableName added in v0.4.0

func (kic *KnowledgeItemContent) TableName() string

TableName is the knowledge item table name in db

type Media

type Media struct {
	Model

	UserID      uint64 `gorm:"column:upload_user_id;not null"`
	Title       string `gorm:"column:title;not null"`
	Slug        string `gorm:"column:slug;not null"`
	Description string `gorm:"column:description;not null"`
	GUID        string `gorm:"column:guid;not null"`
	Type        string `gorm:"column:type;not null;default:picture"`
	MimeType    string `gorm:"column:mime_type;not null"`
	Usage       string `gorm:"column:usage;not null"`
	Status      uint64 `gorm:"column:status;not null;default:1"`
}

MediaModel the definition of media model

func (*Media) BeforeCreate

func (m *Media) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate set values before create Set file type by mime-type

func (*Media) Count

func (m *Media) Count(db *gorm.DB, where string, whereArgs []interface{}) (count int64, err error)

Count count media in condition

func (*Media) Create

func (m *Media) Create(db *gorm.DB) error

Create save the new media file info

func (*Media) Delete

func (m *Media) Delete(db *gorm.DB) error

Delete delete the media info by id (not file right now)

func (*Media) GetByID

func (m *Media) GetByID(db *gorm.DB) error

GetByID get media info by ID

func (*Media) List

func (m *Media) List(db *gorm.DB, where string, whereArgs []interface{}, offset, limit int) (medias []*Media, err error)

List get media list

func (*Media) TableName

func (m *Media) TableName() string

TableName is the resource table name in db

func (*Media) TotalNumber

func (m *Media) TotalNumber(db *gorm.DB) (totalMedia int64, err error)

TotalNumber get total number of media

func (*Media) Update

func (m *Media) Update(db *gorm.DB) (err error)

Update update media info

type Model

type Model struct {
	ID        uint64         `gorm:"primaryKey;autoIncrement;column:id"`
	CreatedAt time.Time      `gorm:"column:created_time;not null"`
	UpdatedAt time.Time      `gorm:"column:updated_time;not null"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_time;DEFAULT null" sql:"index"`
}

Model base model

type Option

type Option struct {
	ID          uint64 `gorm:"primaryKey;autoIncrement;column:id"`
	OptionName  string `gorm:"column:option_name;not null"`
	OptionValue string `gorm:"column:option_value;not null"`
	Autoload    uint64 `gorm:"column:autoload;not null"`
}

Option site options

func (*Option) GetAll added in v0.4.1

func (o *Option) GetAll(db *gorm.DB, optionNames []string) ([]*Option, error)

GetAll get all options by options name

func (*Option) GetAllAutoLoad added in v0.4.1

func (o *Option) GetAllAutoLoad(db *gorm.DB) ([]*Option, error)

GetAllAutoLoad get options need autoload

func (*Option) GetByName

func (o *Option) GetByName(db *gorm.DB) error

GetByName get option by name

func (*Option) Save

func (o *Option) Save(db *gorm.DB) error

Save save option

func (*Option) TableName

func (o *Option) TableName() string

TableName is the resource table name in db

type Post

type Post struct {
	Model

	UserID          uint64       `gorm:"column:user_id;not null"`
	PostType        string       `gorm:"column:post_type;not null;default:article"`
	Title           string       `gorm:"column:title;not null"`
	ContentMarkdown string       `gorm:"column:content_markdown;not null"`
	ContentHTML     string       `gorm:"column:content_html;not null"`
	Slug            string       `gorm:"column:slug;not null"`
	ParentID        uint64       `gorm:"column:parent_id;not null"` // set to 0 now, use for draft history feature in the future
	Status          string       `gorm:"column:status;not null;default:publish"`
	CommentStatus   uint64       `gorm:"column:comment_status;not null;default:1"`
	IfTop           uint64       `gorm:"column:if_top;not null"`
	GUID            string       `gorm:"column:guid;not null"`
	CoverPicture    string       `gorm:"column:cover_picture;not null"`
	CommentCount    uint64       `gorm:"column:comment_count;not null"`
	ViewCount       uint64       `gorm:"column:view_count;not null"`
	PostDate        sql.NullTime `gorm:"column:posted_time;not null"`
}

PostModel is the struct model for post

func (*Post) CheckSlug

func (p *Post) CheckSlug(db *gorm.DB) bool

PageCheckSlugExist check the slug if already exist ErrRecordNotFound => False exist => True

func (*Post) Count

func (p *Post) Count(db *gorm.DB, where string, whereArgs []interface{}) (int64, error)

Count count post

func (*Post) Create

func (p *Post) Create(db *gorm.DB) error

Create creates a post

func (*Post) Delete

func (p *Post) Delete(db *gorm.DB) error

Delete delete a post by ID

func (*Post) GetByID

func (p *Post) GetByID(db *gorm.DB) error

GetByID get post by ID

func (*Post) List

func (p *Post) List(db *gorm.DB, where string, whereArgs []interface{}, offset, number int, order string) ([]*Post, error)

List get post list

func (*Post) Save

func (p *Post) Save(db *gorm.DB) error

Save update a post

func (*Post) TableName

func (p *Post) TableName() string

TableName is the article table name in db

func (*Post) TotalNumber

func (p *Post) TotalNumber(db *gorm.DB, postType string) (totalPost int64, err error)

TotalNumber count total number of post by post type

func (*Post) TotalView

func (p *Post) TotalView(db *gorm.DB) (totalViews int64, err error)

TotalView get total view of all post

type PostMeta

type PostMeta struct {
	ID        uint64 `gorm:"primaryKey;autoIncrement;column:id"`
	PostID    uint64 `gorm:"column:post_id;not null"`
	MetaKey   string `gorm:"column:meta_key;not null"`
	MetaValue string `gorm:"column:meta_value;not null"`
}

PostMetaModel meta data for post

func (*PostMeta) Create

func (p *PostMeta) Create(db *gorm.DB) error

Create

func (*PostMeta) GetAllByPostID

func (p *PostMeta) GetAllByPostID(db *gorm.DB) ([]*PostMeta, error)

GetAllByPostID get all meta data by post id

func (*PostMeta) GetOneByPostID

func (p *PostMeta) GetOneByPostID(db *gorm.DB) error

GetOneByPostID get one specific meta by metakey and post id

func (*PostMeta) Save

func (p *PostMeta) Save(db *gorm.DB) error

Save update a post meata

func (*PostMeta) TableName

func (p *PostMeta) TableName() string

TableName is the article meta data table name in db

type Subject

type Subject struct {
	Model

	ParentID    uint64       `gorm:"column:parent_id;not null"`
	Name        string       `gorm:"column:name;not null"`
	Slug        string       `gorm:"column:slug;not null"`
	Description string       `gorm:"column:description;not null"`
	CoverImage  uint64       `gorm:"column:cover_image;not null"`
	IsEnd       uint64       `gorm:"column:is_end;not null"`
	Count       uint64       `gorm:"column:count;not null"`
	LastUpdated sql.NullTime `gorm:"column:last_updated"`
}

SubjectModel the definition of subject model

func (*Subject) CheckSubjectNameExist

func (s *Subject) CheckSubjectNameExist(db *gorm.DB) bool

CheckSubjectNameExist check the subject name if is already exist

func (*Subject) Create

func (s *Subject) Create(db *gorm.DB) error

Create creates a new subject

func (*Subject) Delete

func (s *Subject) Delete(db *gorm.DB) error

Delete delete subject

func (*Subject) GetAll

func (s *Subject) GetAll(db *gorm.DB) ([]*Subject, error)

GetAll get all subjects

func (*Subject) GetByID

func (s *Subject) GetByID(db *gorm.DB) error

GetByID get subject by ID

func (*Subject) IfSubjectHasChild

func (s *Subject) IfSubjectHasChild(db *gorm.DB, subjectID uint64) bool

IfSubjectHasChild check if subject has children

func (*Subject) Save

func (s *Subject) Save(db *gorm.DB) error

Save update subject

func (*Subject) TableName

func (s *Subject) TableName() string

TableName is the resource table name in db

func (*Subject) Update

func (s *Subject) Update(db *gorm.DB) error

Update update subject

type SubjectRelationships

type SubjectRelationships struct {
	ObjectID  uint64 `gorm:"column:object_id;not null;primaryKey"`
	SubjectID uint64 `gorm:"column:subject_id;not null;primaryKey"`
	OrderNum  string `gorm:"column:order_num;not null"`
}

SubjectRelationshipsModel `pt_subject_relationships` 's struct

func (*SubjectRelationships) DeleteByCondition

func (s *SubjectRelationships) DeleteByCondition(db *gorm.DB, where string, whereArgs []interface{}) error

DeleteByCondition delete records by condition

func (*SubjectRelationships) GetAllByObjectID

func (s *SubjectRelationships) GetAllByObjectID(db *gorm.DB, objectID uint64) ([]*SubjectRelationships, error)

GetAllByObjectID get article's related subject

func (*SubjectRelationships) TableName

func (s *SubjectRelationships) TableName() string

TableName SubjectRelationshipsModel's binding db name

type Term

type Term struct {
	ID          uint64 `gorm:"column:term_id;not null;primary_key"`
	Name        string `gorm:"column:name;not null"`
	Slug        string `gorm:"column:slug;not null"`
	Description string `gorm:"column:description;not null"`
	Count       uint64 `gorm:"column:count;not null"`
}

Term `pt_terms`'s struct for taxomony info

func (*Term) Delete

func (t *Term) Delete(db *gorm.DB) error

func (*Term) GetByID

func (t *Term) GetByID(db *gorm.DB) error

GetByTermID get term info by term_id

func (*Term) Save

func (t *Term) Save(db *gorm.DB) error

func (*Term) TableName

func (t *Term) TableName() string

TableName TermModel's binding db name

func (*Term) Update

func (t *Term) Update(db *gorm.DB, columns ...string) error

type TermRelationships

type TermRelationships struct {
	ObjectID       uint64 `gorm:"column:object_id;not null;primaryKey"`
	TermTaxonomyID uint64 `gorm:"column:term_taxonomy_id;not null;primaryKey"`
	TermOrder      string `gorm:"column:term_order;not null"`
}

TermRelationships `pt_term_relationships` 's struct taxomony raltionships with object

func (*TermRelationships) Delete

func (t *TermRelationships) Delete(db *gorm.DB) error

Delete delete a record

func (*TermRelationships) DeleteByCondition

func (t *TermRelationships) DeleteByCondition(db *gorm.DB, where string, whereArgs []interface{}) error

DeleteByCondition delete records by condition

func (*TermRelationships) TableName

func (c *TermRelationships) TableName() string

TableName TermRelationshipsModel's binding db name

type TermTaxonomy

type TermTaxonomy struct {
	ID           uint64 `gorm:"column:term_taxonomy_id;not null;primaryKey"`
	Term         Term   `gorm:"foreignKey:TermID;references:ID"`
	TermID       uint64 `gorm:"column:term_id;not null"`
	ParentTermID uint64 `gorm:"column:parent_term_id;not null"`
	Level        uint64 `gorm:"column:level;not null;default:1"`
	Taxonomy     string `gorm:"column:taxonomy;not null"`
	TermGroup    uint64 `gorm:"column:term_group;default:0;not null"`
}

TermTaxonomy `pt_term_taxonomy`'s struct

func (*TermTaxonomy) Count

func (t *TermTaxonomy) Count(db *gorm.DB, where string, whereArgs []interface{}) (int64, error)

Count count taxonomy

func (*TermTaxonomy) Create

func (t *TermTaxonomy) Create(db *gorm.DB) error

Create creates a new taxonomy

func (*TermTaxonomy) Delete

func (t *TermTaxonomy) Delete(db *gorm.DB) error

func (*TermTaxonomy) Get

func (t *TermTaxonomy) Get(db *gorm.DB, where string, whereArgs []interface{}) ([]*TermTaxonomy, error)

Get get all by condition

func (*TermTaxonomy) GetAllByType

func (t *TermTaxonomy) GetAllByType(db *gorm.DB, taxomonyType string) ([]*TermTaxonomy, error)

GetAllByType gets terms and taxonomy_terms by type(category, tag)

func (*TermTaxonomy) GetByTermID

func (t *TermTaxonomy) GetByTermID(db *gorm.DB) error

GetByTermID get term taxonomy by term id

func (*TermTaxonomy) GetColumnByTermID

func (t *TermTaxonomy) GetColumnByTermID(db *gorm.DB, columns ...string) error

func (*TermTaxonomy) GetTermTaxonomyByTermID

func (t *TermTaxonomy) GetTermTaxonomyByTermID(db *gorm.DB) error

GetTermTaxonomyByTermID get taxonomy terms info by term_id

func (*TermTaxonomy) Save

func (t *TermTaxonomy) Save(db *gorm.DB) error

func (*TermTaxonomy) TableName

func (t *TermTaxonomy) TableName() string

TableName TermTaxonomyModel's binding db name

func (*TermTaxonomy) Update

func (t *TermTaxonomy) Update(db *gorm.DB, columns ...string) error

type User

type User struct {
	Model

	Username string `gorm:"column:account;unique;not null"  validate:"min=1,max=60"`
	Password string `gorm:"column:password;not null" validate:"min=6,max=255"`
	Nickname string `gorm:"column:nickname;not null"`
	Email    string `gorm:"column:email;unique"`
	Avatar   string `gorm:"column:avatar"`
	PageURL  string `gorm:"column:page_url"`
	Status   int    `gorm:"column:status;default:1" sql:"index"`
	Roles    string `gorm:"column:role;default:subscriber"`
}

User user model

func (*User) Count

func (u *User) Count(db *gorm.DB, where string, whereArgs []interface{}) (int64, error)

Count count user

func (*User) Create

func (u *User) Create(db *gorm.DB) error

Create creates a new user account

func (*User) Delete

func (u *User) Delete(db *gorm.DB) error

Delete delete a user by id

func (*User) Encrypt

func (u *User) Encrypt() (err error)

Encrypt the user password.

func (*User) Get

func (u *User) Get(db *gorm.DB) error

Get get an user by the user identifier

func (*User) GetByID

func (u *User) GetByID(db *gorm.DB) error

GetByID get user by ID

func (*User) List

func (u *User) List(db *gorm.DB, where string, whereArgs []interface{}, offset, number int) ([]*User, error)

List get user list

func (*User) TableName

func (u *User) TableName() string

TableName is the user table name in db

func (*User) Update

func (u *User) Update(db *gorm.DB) error

Update updates an user account information

Jump to

Keyboard shortcuts

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