mixin

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Default     = BoolMixin{Field: "default", Comment: "is default", Optional: true}
	Markdown    = BoolMixin{Field: "markdown", Comment: "is markdown", Optional: true}
	Temp        = BoolMixin{Field: "temp", Comment: "is temp", Optional: true}
	Private     = BoolMixin{Field: "private", Comment: "is private", Optional: true}
	Approved    = BoolMixin{Field: "approved", Comment: "is approved", Optional: true}
	Disabled    = BoolMixin{Field: "disabled", Comment: "is disabled", Optional: true}
	Logged      = BoolMixin{Field: "logged", Comment: "is logged", Optional: true}
	System      = BoolMixin{Field: "system", Comment: "is system", Optional: true}
	Hidden      = BoolMixin{Field: "hidden", Comment: "is hidden", Optional: true}
	IsCertified = BoolMixin{Field: "is_certified", Comment: "is certified", Optional: true}
	IsAdmin     = BoolMixin{Field: "is_admin", Comment: "is admin", Optional: true}
	Autoload    = BoolMixin{Field: "autoload", Comment: "Whether to load the option automatically", Default: true, Optional: true}
	Read        = BoolMixin{Field: "read", Comment: "is read", Optional: true}
	ReadWrite   = BoolMixin{Field: "read_write", Comment: "is read write", Optional: true}
	Write       = BoolMixin{Field: "write", Comment: "is write", Optional: true}
)

Specific mixins can be created using the generic BoolMixin.

View Source
var (
	Status        = IntField{Field: "status", Comment: "status: 0 activated, 1 unactivated, 2 disabled", Default: 0}
	Order         = IntField{Field: "order", Comment: "display order", Default: 0}
	Size          = IntField{Field: "size", Comment: "size in bytes", Default: 0}
	IncrementStep = IntField{Field: "increment_step", Comment: "Increment step", Default: 1}
	StartValue    = IntField{Field: "start_value", Comment: "Start value", Default: 1}
	CurrentValue  = IntField{Field: "current_value", Comment: "Current value", Default: 0}
	RetryLimit    = IntField{Field: "retry_limit", Comment: "max retry times", Default: 0}
	RetryDelay    = IntField{Field: "retry_delay", Comment: "retry delay in seconds", Default: 0}
	RemindTime    = IntField{Field: "remind_time", Comment: "remind time before due", Default: 0}
)

Specific mixins can be created using the generic BoolMixin.

View Source
var (
	ExtraProps = JSONMixin{Field: "extras", Default: types.JSON{}, Comment: "Extend properties", Optional: true}
	Author     = JSONMixin{Field: "author", Default: types.JSON{}, Comment: "Author information, e.g., {id: '', name: '', avatar: '', url: '', email: '', ip: ''}", Optional: true}
	Related    = JSONMixin{Field: "related", Default: types.JSON{}, Comment: "Related entity information, e.g., {id: '', name: '', type: 'user / topic /...'}", Optional: true}
	Leader     = JSONMixin{Field: "leader", Default: types.JSON{}, Comment: "Leader information, e.g., {id: '', name: '', avatar: '', url: '', email: '', ip: ''}", Optional: true}
	Links      = JSONMixin{Field: "links", Default: types.JSONArray{}, Comment: "List of social links or profile links", Optional: true}
	Payload    = JSONMixin{Field: "payload", Default: types.JSON{}, Comment: "Payload", Optional: true}
	Metadata   = JSONMixin{Field: "metadata", Default: types.JSON{}, Comment: "Metadata", Optional: true}
)

Specific mixins can be created using the generic JSONMixin.

View Source
var (
	UserID         = IDMixin{Field: "user_id", Comment: "user id", MaxLen: consts.PrimaryKeySize}
	RoleID         = IDMixin{Field: "role_id", Comment: "role id", MaxLen: consts.PrimaryKeySize}
	PermissionID   = IDMixin{Field: "permission_id", Comment: "permission id", MaxLen: consts.PrimaryKeySize}
	GroupID        = IDMixin{Field: "group_id", Comment: "group id", MaxLen: consts.PrimaryKeySize}
	TenantID       = IDMixin{Field: "tenant_id", Comment: "tenant id", MaxLen: consts.PrimaryKeySize}
	OrganizationID = IDMixin{Field: "organization_id", Comment: "organization id", MaxLen: consts.PrimaryKeySize}
	ParentID       = IDMixin{Field: "parent_id", Comment: "parent id", MaxLen: consts.PrimaryKeySize}
	TopicID        = IDMixin{Field: "topic_id", Comment: "topic id", MaxLen: consts.PrimaryKeySize}
	ReplyToMixin   = IDMixin{Field: "reply_to", Comment: "reply to object id", MaxLen: consts.PrimaryKeySize}
	TaxonomyID     = IDMixin{Field: "taxonomy_id", Comment: "taxonomy id", MaxLen: consts.PrimaryKeySize}
	StoreID        = IDMixin{Field: "store_id", Comment: "store id", MaxLen: consts.PrimaryKeySize}
	CatalogID      = IDMixin{Field: "catalog_id", Comment: "catalog id", MaxLen: consts.PrimaryKeySize}
	ObjectID       = IDMixin{Field: "object_id", Comment: "object id", MaxLen: consts.PrimaryKeySize}
	OAuthID        = IDMixin{Field: "oauth_id", Comment: "oauth id"}
	ChannelID      = IDMixin{Field: "channel_id", Comment: "channel id", MaxLen: consts.PrimaryKeySize}
)

Specific mixins can be created using the generic IDMixin.

View Source
var (
	TextStatus     = StringMixin{Field: "status", Comment: "Status, text status", Optional: true}
	Email          = StringMixin{Field: "email", Comment: "email", Optional: true}
	Username       = StringMixin{Field: "username", Comment: "username", Optional: true}
	UsernameUnique = StringMixin{Field: "username", Comment: "username", Unique: true, NotEmpty: true, Optional: true, MaxLen: 50, MatchRegex: regexp.MustCompile("^[a-zA-Z0-9]{4,16}$")}
	Password       = StringMixin{Field: "password", Comment: "password", Sensitive: true, Optional: true}
	Secret         = StringMixin{Field: "secret", Comment: "secret key", Optional: true}
	Phone          = StringMixin{Field: "phone", Comment: "phone", Optional: true}
	BankName       = StringMixin{Field: "bank_name", Comment: "bank name", Optional: true}
	CardNo         = StringMixin{Field: "card_no", Comment: "card no", Optional: true}
	CCV            = StringMixin{Field: "ccv", Comment: "ccv", Optional: true}
	Province       = StringMixin{Field: "province", Comment: "province", Optional: true}
	ZipCode        = StringMixin{Field: "zip_code", Comment: "zip code", Optional: true}
	City           = StringMixin{Field: "city", Comment: "city", Optional: true}
	District       = StringMixin{Field: "district", Comment: "district", Optional: true}
	Address        = StringMixin{Field: "address", Comment: "address", Optional: true}
	FirstName      = StringMixin{Field: "first_name", Comment: "first name", Optional: true}
	LastName       = StringMixin{Field: "last_name", Comment: "last name", Optional: true}
	DisplayName    = StringMixin{Field: "display_name", Comment: "display name", Optional: true}
	Language       = StringMixin{Field: "language", Comment: "language", Optional: true}
	About          = StringMixin{Field: "about", Comment: "about", Optional: true}
	Identifier     = StringMixin{Field: "identifier", Comment: "Identifier", Optional: true, NotEmpty: true}
	Name           = StringMixin{Field: "name", Comment: "name", Optional: true}
	NameUnique     = StringMixin{Field: "name", Comment: "name", Unique: true, NotEmpty: true, Optional: true}
	Prefix         = StringMixin{Field: "prefix", Comment: "prefix", Optional: true}
	Suffix         = StringMixin{Field: "suffix", Comment: "suffix", Optional: true}
	Label          = StringMixin{Field: "label", Comment: "label", Optional: true}
	Code           = StringMixin{Field: "code", Comment: "code", Optional: true}
	Slug           = StringMixin{Field: "slug", Comment: "slug / alias", Optional: true}
	SlugUnique     = StringMixin{Field: "slug", Comment: "slug / alias", Unique: true, Optional: true}
	Cover          = StringMixin{Field: "cover", Comment: "cover", Optional: true}
	Thumbnail      = StringMixin{Field: "thumbnail", Comment: "thumbnail", Optional: true}
	Path           = StringMixin{Field: "path", Comment: "path", Optional: true}
	Target         = StringMixin{Field: "target", Comment: "target", Optional: true}
	URL            = StringMixin{Field: "url", Comment: "url, website / link...", Optional: true}
	Icon           = StringMixin{Field: "icon", Comment: "icon", Optional: true}
	Perms          = StringMixin{Field: "perms", Comment: "perms", Optional: true}
	Color          = StringMixin{Field: "color", Comment: "color", Optional: true}
	Content        = StringMixin{Field: "content", Comment: "content, big text", Optional: true}
	Keywords       = StringMixin{Field: "keywords", Comment: "keywords", Optional: true}
	Copyright      = StringMixin{Field: "copyright", Comment: "copyright", Optional: true}
	LogoAlt        = StringMixin{Field: "logo_alt", Comment: "logo alt", Optional: true}
	Type           = StringMixin{Field: "type", Comment: "type", Optional: true}
	Storage        = StringMixin{Field: "storage", Comment: "storage type", Optional: true}
	Bucket         = StringMixin{Field: "bucket", Comment: "bucket", Optional: true}
	Endpoint       = StringMixin{Field: "endpoint", Comment: "endpoint", Optional: true}
	Action         = StringMixin{Field: "action", Comment: "action", Optional: true}
	Subject        = StringMixin{Field: "subject", Comment: "subject", Optional: true}
	Provider       = StringMixin{Field: "provider", Comment: "provider", Optional: true}
	AccessToken    = StringMixin{Field: "access_token", Comment: "access token", NotEmpty: true}
	RefreshToken   = StringMixin{Field: "refresh_token", Comment: "refresh token", NotEmpty: true}
	SessionID      = StringMixin{Field: "session_id", Comment: "session id", Optional: true}
	ShortBio       = StringMixin{Field: "short_bio", Comment: "short bio", Optional: true}
	Bio            = StringMixin{Field: "bio", Comment: "bio", Optional: true}
	Hash           = StringMixin{Field: "hash", Comment: "hash", Optional: true}
	Title          = StringMixin{Field: "title", Comment: "title", Optional: true}
	Caption        = StringMixin{Field: "caption", Comment: "caption", Optional: true}
	MediaType      = StringMixin{Field: "mime", Comment: "resource type", Optional: true}
	ExtensionName  = StringMixin{Field: "ext", Comment: "extension name", Optional: true}
	Memo           = StringMixin{Field: "memo", Comment: "Memo, big text", Optional: true}
	Remark         = StringMixin{Field: "remark", Comment: "Remark, big text", Optional: true}
	PType          = StringMixin{Field: "p_type", Comment: "permission type", Optional: true}
	Version        = StringMixin{Field: "version", Comment: "Version", Optional: true}
	V0             = StringMixin{Field: "v0", Comment: "version 0", Optional: true}
	V1             = StringMixin{Field: "v1", Comment: "version 1", Optional: true}
	V2             = StringMixin{Field: "v2", Comment: "version 2", Optional: true}
	V3             = StringMixin{Field: "v3", Comment: "version 3", Optional: true}
	V4             = StringMixin{Field: "v4", Comment: "version 4", Optional: true}
	V5             = StringMixin{Field: "v5", Comment: "version 5", Optional: true}
	V6             = StringMixin{Field: "v6", Comment: "version 6", Optional: true}
	V7             = StringMixin{Field: "v7", Comment: "version 7", Optional: true}
	CreatedBy      = StringMixin{Field: "created_by", Comment: "id of the creator", Optional: true, MaxLen: consts.PrimaryKeySize}
	UpdatedBy      = StringMixin{Field: "updated_by", Comment: "id of the last updater", Optional: true, MaxLen: consts.PrimaryKeySize}
	DeletedBy      = StringMixin{Field: "deleted_by", Comment: "id of the deleter", Optional: true, MaxLen: consts.PrimaryKeySize}
)

Specific mixins can be created using the generic StringMixin.

View Source
var (
	Value       = TextMixin{Field: "value", Comment: "value", Optional: true}
	Description = TextMixin{Field: "description", Comment: "description", Optional: true}
)

Specific mixins can be created using the generic TextMixin.

View Source
var (
	CreatedAt = TimeMixin{
		Field:     "created_at",
		Comment:   "created at",
		Default:   func() int64 { return time.Now().UnixMilli() },
		Immutable: true,
		Optional:  true,
	}
	UpdatedAt = TimeMixin{
		Field:         "updated_at",
		Comment:       "updated at",
		Default:       func() int64 { return time.Now().UnixMilli() },
		UpdateDefault: func() int64 { return time.Now().UnixMilli() },
		Optional:      true,
	}
	DeletedAt   = TimeMixin{Field: "deleted_at", Comment: "deleted at", Optional: true}
	ExpiredAt   = TimeMixin{Field: "expired_at", Comment: "expired at", Optional: true}
	Expires     = TimeMixin{Field: "expires", Comment: "expires", Optional: true}
	Released    = TimeMixin{Field: "released", Comment: "released", Optional: true}
	StartedAt   = TimeMixin{Field: "started_at", Comment: "started time", Default: func() int64 { return time.Now().UnixMilli() }}
	CompletedAt = TimeMixin{Field: "completed_at", Comment: "completed time", Optional: true}
)

Specific mixins can be created using the generic TimeMixin.

View Source
var (
	Operator = OperatorBy{}
)

Operator Specific mixins can be created using the generic OperatorBy.

View Source
var PrimaryKey = StringMixin{
	Field:       "id",
	Comment:     "primary key",
	Immutable:   true,
	Unique:      true,
	MaxLen:      consts.PrimaryKeySize,
	DefaultFunc: nanoid.PrimaryKey(),
}

Functions

This section is empty.

Types

type BoolMixin

type BoolMixin struct {
	mixin.Schema
	Field     string
	Comment   string
	Default   bool
	Immutable bool
	Optional  bool
}

BoolMixin defines a generic boolean field mixin.

func (BoolMixin) Fields

func (m BoolMixin) Fields() []ent.Field

Fields implements the ent.Mixin interface for BoolMixin.

type BusinessFlowMixin

type BusinessFlowMixin struct {
	mixin.Schema
}

BusinessFlowMixin defines common business flow status fields

func (BusinessFlowMixin) Fields

func (BusinessFlowMixin) Fields() []ent.Field

type BusinessTagMixin

type BusinessTagMixin struct {
	mixin.Schema
}

BusinessTagMixin defines common business tagging fields

func (BusinessTagMixin) Fields

func (BusinessTagMixin) Fields() []ent.Field

type DataTrackingMixin

type DataTrackingMixin struct {
	mixin.Schema
}

DataTrackingMixin defines common data tracking fields

func (DataTrackingMixin) Fields

func (DataTrackingMixin) Fields() []ent.Field

type FormBaseMixin

type FormBaseMixin struct {
	mixin.Schema
}

FormBaseMixin defines common form-related fields

func (FormBaseMixin) Fields

func (FormBaseMixin) Fields() []ent.Field

type IDMixin

type IDMixin struct {
	ent.Schema
	Field      string
	Comment    string
	StorageKey string
	MaxLen     int
}

IDMixin is a generic mixin for adding an ID field.

func (IDMixin) Fields

func (m IDMixin) Fields() []ent.Field

Fields of the IDMixin.

func (IDMixin) Indexes

func (m IDMixin) Indexes() []ent.Index

Indexes of the IDMixin.

type IntField

type IntField struct {
	mixin.Schema
	Field    string
	Comment  string
	Default  int
	Positive bool
}

IntField defines a generic boolean field mixin.

func (IntField) Fields

func (m IntField) Fields() []ent.Field

Fields implements the ent.Mixin interface for IntField.

type JSONMixin

type JSONMixin struct {
	ent.Schema
	Field    string
	Default  any
	Comment  string
	Optional bool
}

JSONMixin defines a generic JSON field mixin.

func (JSONMixin) Fields

func (m JSONMixin) Fields() []ent.Field

Fields implements the ent.Mixin interface for JSONMixin.

type NodeBaseMixin

type NodeBaseMixin struct {
	mixin.Schema
}

NodeBaseMixin defines common node-related fields

func (NodeBaseMixin) Fields

func (NodeBaseMixin) Fields() []ent.Field

type OperatorBy

type OperatorBy struct{ mixin.Schema }

OperatorBy combines CreatedBy, UpdatedBy, and DeletedBy fields into a single mixin.

func (OperatorBy) Fields

func (OperatorBy) Fields() []ent.Field

Fields of the OperatorBy mixin.

type PermissionMixin

type PermissionMixin struct {
	mixin.Schema
}

PermissionMixin defines common permission fields

func (PermissionMixin) Fields

func (PermissionMixin) Fields() []ent.Field

type PrimaryKeyAlias

type PrimaryKeyAlias struct {
	ent.Schema
	AliasName string
	AliasKey  string
}

PrimaryKeyAlias adds a primary key alias field.

func NewPrimaryKeyAlias

func NewPrimaryKeyAlias(aliasName, aliasKey string) PrimaryKeyAlias

NewPrimaryKeyAlias creates a new PrimaryKeyAlias mixin with the given alias name and key.

func (PrimaryKeyAlias) Fields

func (m PrimaryKeyAlias) Fields() []ent.Field

Fields of the primary key alias mixin.

func (PrimaryKeyAlias) Indexes

func (m PrimaryKeyAlias) Indexes() []ent.Index

Indexes of the PrimaryKeyAlias.

type ProcessRefMixin

type ProcessRefMixin struct {
	mixin.Schema
}

ProcessRefMixin defines common process reference fields

func (ProcessRefMixin) Fields

func (ProcessRefMixin) Fields() []ent.Field

type StringMixin

type StringMixin struct {
	mixin.Schema
	Field       string
	Comment     string
	StorageKey  string
	Nillable    bool
	Optional    bool
	Unique      bool
	NotEmpty    bool
	Immutable   bool
	MaxLen      int
	MatchRegex  *regexp.Regexp
	Sensitive   bool
	DefaultFunc any
	Default     string
}

StringMixin is a generic mixin for adding various fields.

func DateFormat

func DateFormat(f ...string) StringMixin

DateFormat default date format

func (StringMixin) Fields

func (m StringMixin) Fields() []ent.Field

Fields of the StringMixin.

func (StringMixin) Indexes

func (m StringMixin) Indexes() []ent.Index

Indexes of the StringMixin.

type TaskAssigneeMixin

type TaskAssigneeMixin struct {
	mixin.Schema
}

TaskAssigneeMixin defines common task assignee fields

func (TaskAssigneeMixin) Fields

func (TaskAssigneeMixin) Fields() []ent.Field

type TextMixin

type TextMixin struct {
	mixin.Schema
	Field       string
	Comment     string
	StorageKey  string
	Nillable    bool
	Optional    bool
	Unique      bool
	NotEmpty    bool
	Immutable   bool
	MaxLen      int
	MatchRegex  *regexp.Regexp
	Sensitive   bool
	DefaultFunc any
}

TextMixin is a generic mixin for adding various fields.

func (TextMixin) Fields

func (m TextMixin) Fields() []ent.Field

Fields of the TextMixin.

func (TextMixin) Indexes

func (m TextMixin) Indexes() []ent.Index

Indexes of the TextMixin.

type TimeAt

type TimeAt struct{ mixin.Schema }

TimeAt composes created_at and updated_at time fields.

func (TimeAt) Fields

func (TimeAt) Fields() []ent.Field

Fields of the TimeAt mixin.

type TimeMixin

type TimeMixin struct {
	mixin.Schema
	Field         string
	Comment       string
	Default       func() int64
	UpdateDefault func() int64
	Optional      bool
	Immutable     bool
}

TimeMixin defines a generic time field mixin.

func (TimeMixin) Fields

func (m TimeMixin) Fields() []ent.Field

Fields implements the ent.Mixin interface for TimeMixin.

type TimeTrackingMixin

type TimeTrackingMixin struct {
	mixin.Schema
}

TimeTrackingMixin defines common time tracking fields

func (TimeTrackingMixin) Fields

func (TimeTrackingMixin) Fields() []ent.Field

type WorkflowControlMixin

type WorkflowControlMixin struct {
	mixin.Schema
}

WorkflowControlMixin defines common workflow control fields

func (WorkflowControlMixin) Fields

func (WorkflowControlMixin) Fields() []ent.Field

Jump to

Keyboard shortcuts

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