model

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NowFN = func() string {
	return time.Now().String()
}
View Source
var UUIDFN = func() string {
	return strings.ReplaceAll(uuid.New().String(), "-", "")
}

Functions

This section is empty.

Types

type DefaultFN

type DefaultFN string
const (
	UUID DefaultFN = "uuid"
	Now  DefaultFN = "now"
)

type Field

type Field struct {
	ModelID                string          `json:"modelID,omitempty" yaml:"modelID" binding:"required" gorm:"column:model_id;type:varchar(64);not null;comment:模型id"`
	Name                   string          `json:"name" yaml:"name" binding:"required"`
	JsonTag                string          `json:"jsonTag" yaml:"jsonTag"`
	DataType               schema.DataType `json:"type" yaml:"type" binding:"required"`
	PrimaryKey             string          `json:"primaryKey" yaml:"primaryKey"`
	AutoIncrement          bool            `json:"autoIncrement" yaml:"autoIncrement"`
	AutoIncrementIncrement int64           `json:"autoIncrementIncrement" yaml:"autoIncrementIncrement"`
	Creatable              bool            `json:"creatable" yaml:"creatable"`
	Updatable              bool            `json:"updatable" yaml:"updatable"`
	Readable               bool            `json:"readable" yaml:"readable"`
	DefaultValue           string          `json:"defaultValue" yaml:"defaultValue"`
	DefaultValueFN         func() string   `json:"-" yaml:"-"`
	NotNull                bool            `json:"notNull" yaml:"notNull"`
	Unique                 string          `json:"unique" yaml:"unique"`
	Index                  string          `json:"index" yaml:"index"`
	Comment                string          `json:"comment" yaml:"comment"`
	Size                   int             `json:"size" yaml:"size"`
	Precision              int             `json:"precision" yaml:"precision"`
	Scale                  int             `json:"scale" yaml:"scale"`
	Search                 string          `json:"search" yaml:"search"`
}

func (*Field) GenOpenAPIFie added in v0.1.0

func (f *Field) GenOpenAPIFie() *spec.Schema

func (*Field) GetName

func (f *Field) GetName() string

func (*Field) Init

func (f *Field) Init()

func (*Field) MakeField

func (f *Field) MakeField() reflect.StructField

type Model

type Model struct {
	Table       string   `json:"tableName" yaml:"tableName" binding:"required"`
	Name        string   `json:"name" yaml:"name" binding:"required"`
	Description string   `json:"description" yaml:"description"`
	HardDeleted bool     `json:"hardDeleted" yaml:"hardDeleted"`
	Fields      []*Field `json:"fields" yaml:"fields" binding:"required"`
	MultiTenant bool     `json:"multiTenant" yaml:"multiTenant"`
	Auth        bool     `json:"auth" yaml:"auth"`
}

func (*Model) Default

func (m *Model) Default(data any)

func (*Model) GenOpenAPIModel added in v0.1.0

func (m *Model) GenOpenAPIModel() *spec.Schema

func (*Model) Init

func (m *Model) Init()

func (*Model) MakeField

func (m *Model) MakeField() []reflect.StructField

func (*Model) MakeList

func (m *Model) MakeList() any

func (*Model) MakeModel

func (m *Model) MakeModel() any

MakeModel make virtual model

func (*Model) MakeTimeField

func (m *Model) MakeTimeField() []reflect.StructField

func (*Model) Migrate

func (m *Model) Migrate(db *gorm.DB) error

func (*Model) Pagination

func (m *Model) Pagination(ctx *gin.Context, p PaginationImp) (f func(*gorm.DB) *gorm.DB)

func (*Model) PrimaryKeys

func (m *Model) PrimaryKeys() []string

PrimaryKeys get primary keys support multi keys

func (*Model) Search

func (m *Model) Search(ctx *gin.Context) (f func(*gorm.DB) *gorm.DB)

func (*Model) TableName

func (m *Model) TableName() string

TableName get table name

func (*Model) TableScope

func (m *Model) TableScope(db *gorm.DB) *gorm.DB

func (*Model) TenantScope added in v0.1.4

func (m *Model) TenantScope(ctx *gin.Context,
	fn func(ctx *gin.Context) (any, error)) func(db *gorm.DB) *gorm.DB

func (*Model) URI

func (m *Model) URI(ctx *gin.Context) (f func(*gorm.DB) *gorm.DB)

type ModelImpl added in v0.1.0

type ModelImpl interface {
	mgm.Model
	schema.Tabler
}

ModelImpl gorm and mgm model

type ModelProvider added in v0.1.0

type ModelProvider string

ModelProvider model provider

const (
	// ModelProviderMgm mgm model provider
	ModelProviderMgm ModelProvider = "mgm"
	// ModelProviderGorm gorm model provider
	ModelProviderGorm ModelProvider = "gorm"
)

type PaginationImp

type PaginationImp interface {
	GetPage() int64
	GetPageSize() int64
}

Jump to

Keyboard shortcuts

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