model

package
v0.0.0-...-96504fd Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IDKey        = "_id"
	CreatedAtKey = "created_at"
	// CreatedByKey = "created_by"
	UpdatedAtKey = "updated_at"
	DeletedAtKey = "deleted_at"
)

Variables

View Source
var Common = &common{}
View Source
var Inside = &inside{}

Functions

func Delete

func Delete[T Filter](m *Model, filter T, fn ...func(*CondOptions) error) (int64, error)

func DeleteMany

func DeleteMany[T Filter](m *Model, filter T, fn ...func(*CondOptions) error) (int64, error)

func Find

func Find[T Filter](m *Model, filter T, fn ...func(*CondOptions) error) (ztype.Maps, error)

func FindCol

func FindCol[T Filter](m *Model, field string, filter T, fn ...func(*CondOptions) error) (ztype.Type, bool, error)

func FindCols

func FindCols[T Filter](m *Model, field string, filter T, fn ...func(*CondOptions) error) (ztype.SliceType, error)

func FindOne

func FindOne[T Filter](m *Model, filter T, fn ...func(*CondOptions) error) (ztype.Map, error)

func Insert

func Insert(m *Model, data ztype.Map) (lastId interface{}, err error)

func InsertMany

func InsertMany(m *Model, datas ztype.Maps) (lastIds []interface{}, err error)

func Update

func Update[T Filter](m *Model, filter T, data ztype.Map, fn ...func(*CondOptions) error) (total int64, err error)

func UpdateMany

func UpdateMany[T Filter](m *Model, filter T, data ztype.Map, fn ...func(*CondOptions) error) (total int64, err error)

func Upload

func Upload(c *znet.Context, o ...func(options *UploadOptions)) (files []string, err error)

Upload Upload file

func VerifiData

func VerifiData(data ztype.Map, columns define.Fields, active activeType) (ztype.Map, error)

VerifiData 验证数据

Types

type ColumnEnum

type ColumnEnum struct {
	Value string `json:"value"`
	Label string `json:"label"`
}

type CondOptions

type CondOptions struct {
	Fields  []string
	GroupBy []string
	OrderBy map[string]string
	Join    []StorageJoin
	Limit   int
}

type CryptProcess

type CryptProcess func(string) (string, error)

type DataTime

type DataTime struct {
	time.Time
}

func (DataTime) MarshalJSON

func (t DataTime) MarshalJSON() ([]byte, error)

func (*DataTime) Scan

func (t *DataTime) Scan(v interface{}) error

func (*DataTime) String

func (t *DataTime) String() string

func (*DataTime) UnmarshalJSON

func (t *DataTime) UnmarshalJSON(data []byte) error

func (DataTime) Value

func (t DataTime) Value() (driver.Value, error)

type DealOldColumn

type DealOldColumn uint8
const (
	DealOldColumnNone DealOldColumn = iota
	DealOldColumnDelete
	DealOldColumnRename
)

type Filter

type Filter interface {
	ztype.Map | constraints.Integer | string
}

type Migration

type Migration struct {
	Model *Model
	DB    *zdb.DB
}

func (*Migration) Auto

func (m *Migration) Auto(oldColumn DealOldColumn) (err error)

func (*Migration) CreateTable

func (m *Migration) CreateTable() error

func (*Migration) HasTable

func (m *Migration) HasTable() bool

func (*Migration) Indexs

func (m *Migration) Indexs() error

func (*Migration) InitValue

func (m *Migration) InitValue(first bool) error

func (*Migration) UpdateTable

func (m *Migration) UpdateTable(oldColumn DealOldColumn) error

type Migrationer

type Migrationer interface {
	Auto(deleteColumn DealOldColumn) (err error)
	HasTable() bool
}

type Model

type Model struct {
	Storage Storageer

	Hashid *hashid.HashID `json:"-"`

	JSONPath string

	JSON        []byte
	Fields      []string `json:"-"`
	StorageType StorageType
	// contains filtered or unexported fields
}

func (*Model) Alias

func (m *Model) Alias() string

func (*Model) DI

func (m *Model) DI() zdi.Injector

func (*Model) DeCrypt

func (m *Model) DeCrypt(row ztype.Map) (err error)

DeCrypt 解密 ID

func (*Model) DeCryptID

func (m *Model) DeCryptID(nid string) (id string, err error)

DeCryptID 解密 ID

func (*Model) Define

func (m *Model) Define() define.Define

func (*Model) EnCrypt

func (m *Model) EnCrypt(row *ztype.Map) (err error)

EnCrypt 加密 ID

func (*Model) EnCryptID

func (m *Model) EnCryptID(id string) (nid string, err error)

EnCryptID 加密 ID

func (*Model) GetAfterProcess

func (m *Model) GetAfterProcess(p []string) (fn []afterProcess, err error)

func (*Model) GetBeforeProcess

func (m *Model) GetBeforeProcess(p []string) (fn []beforeProcess, err error)

func (*Model) GetCryptProcess

func (m *Model) GetCryptProcess(cryptName string) (fn CryptProcess, err error)

func (*Model) GetField

func (m *Model) GetField(name string) (define.Field, bool)

func (*Model) GetFields

func (m *Model) GetFields(exclude ...string) []string

func (*Model) GetModelFields

func (m *Model) GetModelFields() define.Fields

func (*Model) GetViewFields

func (m *Model) GetViewFields(view string) []string

func (*Model) GetViews

func (m *Model) GetViews() ztype.Map

func (*Model) Migration

func (m *Model) Migration() Migrationer

func (*Model) Name

func (m *Model) Name() string

func (*Model) Operation

func (m *Model) Operation() *Operation

func (*Model) TableName

func (m *Model) TableName() string

type Models

type Models struct {
	// contains filtered or unexported fields
}

func NewModels

func NewModels(di zdi.Injector, s Storageer) *Models

func (*Models) BatchReg

func (ms *Models) BatchReg(models map[string]define.Define, force bool) error

func (*Models) ForEach

func (ms *Models) ForEach(fn func(key string, m *Model) bool)

func (*Models) Get

func (ms *Models) Get(alias string) (*Model, bool)

func (*Models) Reg

func (ms *Models) Reg(name string, data define.Define, force bool) (*Model, error)

func (*Models) Storage

func (ms *Models) Storage() Storageer

type Module

type Module struct {
	service.ModuleLifeCycle
	// Operations *Operations
	// Models  *Models
	Options Options
}

func New

func New(o ...func(*Options)) (m *Module)

func (*Module) Name

func (p *Module) Name() string

type Operation

type Operation struct {
	// contains filtered or unexported fields
}

func (*Operation) Count

func (o *Operation) Count(filter ztype.Map) (int64, error)

Count 统计数量

func (*Operation) DeCryptID

func (o *Operation) DeCryptID(nid string) (id string, err error)

DeCryptID 解密 ID

func (*Operation) Delete

func (o *Operation) Delete(id any, filter ztype.Map, fn ...func(*CondOptions) error) (total int64, err error)

Delete 删除数据

func (*Operation) DeleteByID

func (o *Operation) DeleteByID(id any, fn ...func(*CondOptions) error) (total int64, err error)

DeleteByID 通过ID删除数据

func (*Operation) DeleteMany

func (o *Operation) DeleteMany(id any, filter ztype.Map, fn ...func(*CondOptions) error) (total int64, err error)

DeleteMany 删除多条数据

func (*Operation) EnCryptID

func (o *Operation) EnCryptID(id string) (nid string, err error)

EnCryptID 加密 ID

func (*Operation) Exists

func (o *Operation) Exists(filter ztype.Map) (bool, error)

Exists 数据是否存在

func (*Operation) Find

func (o *Operation) Find(filter ztype.Map, fn ...func(*CondOptions) error) (ztype.Maps, error)

Find 查询数据

func (*Operation) FindCols

func (o *Operation) FindCols(field string, filter ztype.Map) (ztype.SliceType, error)

FindCols 查询指定字段

func (*Operation) FindOne

func (o *Operation) FindOne(filter ztype.Map, fn ...func(*CondOptions) error) (ztype.Map, error)

FindOne 查询一条数据

func (*Operation) FindOneByID

func (o *Operation) FindOneByID(id any, fn ...func(*CondOptions) error) (ztype.Map, error)

FindOneByID 通过ID查询

func (*Operation) Insert

func (o *Operation) Insert(data ztype.Map) (lastId interface{}, err error)

Insert 插入数据

func (*Operation) InsertMany

func (o *Operation) InsertMany(data ztype.Maps) (lastId interface{}, err error)

InsertMany 批量插入数据

func (*Operation) Pages

func (o *Operation) Pages(page, pagesize int, filter ztype.Map, fn ...func(*CondOptions) error) (*PageData, error)

Pages 分页查询

func (*Operation) Update

func (o *Operation) Update(filter ztype.Map, data ztype.Map, fn ...func(*CondOptions) error) (total int64, err error)

Update 更新数据

func (*Operation) UpdateByID

func (o *Operation) UpdateByID(id any, data ztype.Map, fn ...func(*CondOptions) error) (total int64, err error)

UpdateByID 通过ID更新

func (*Operation) UpdateMany

func (o *Operation) UpdateMany(filter ztype.Map, data ztype.Map, fn ...func(*CondOptions) error) (total int64, err error)

UpdateMany 更新多条数据

type Operations

type Operations struct {
	// contains filtered or unexported fields
}

func (*Operations) Get

func (m *Operations) Get(name string) (*Operation, bool)

Get 获取操作对象

type Options

type Options struct {
	Prefix           string
	ModelsDefine     []define.Define
	DisabledMigrator bool
	GetDB            func() (*zdb.DB, error)
}

type PageData

type PageData struct {
	Items ztype.Maps `json:"items"`
	Page  PageInfo   `json:"page"`
}

func Pages

func Pages[T Filter](m *Model, page, pagesize int, filter T, fn ...func(*CondOptions) error) (*PageData, error)

type PageInfo

type PageInfo struct {
	zdb.Pages
}

type SQL

type SQL struct {
	Options SQLOptions
	// contains filtered or unexported fields
}

func (*SQL) Delete

func (s *SQL) Delete(table string, filter ztype.Map, fn ...func(*CondOptions) error) (int64, error)

func (*SQL) Find

func (s *SQL) Find(table string, filter ztype.Map, fn ...func(*CondOptions) error) (ztype.Maps, error)

func (*SQL) First

func (s *SQL) First(table string, filter ztype.Map, fn ...func(*CondOptions) error) (ztype.Map, error)

func (*SQL) GetStorageType

func (s *SQL) GetStorageType() StorageType

func (*SQL) Insert

func (s *SQL) Insert(table string, data ztype.Map) (lastId interface{}, err error)

func (*SQL) InsertMany

func (s *SQL) InsertMany(table string, data ztype.Maps) (lastIds []interface{}, err error)

func (*SQL) Migration

func (s *SQL) Migration(model *Model) Migrationer

func (*SQL) Pages

func (s *SQL) Pages(table string, page, pagesize int, filter ztype.Map, fn ...func(*CondOptions) error) (ztype.Maps, PageInfo, error)

func (*SQL) Update

func (s *SQL) Update(table string, data ztype.Map, filter ztype.Map, fn ...func(*CondOptions) error) (int64, error)

type SQLOptions

type SQLOptions struct {
	Prefix string
}

type StorageJoin

type StorageJoin struct {
	Table        string
	As           string
	Expr         string
	ModelOptions builder.JoinOption
}

type StorageModelOptions

type StorageModelOptions struct {
}

type StorageType

type StorageType uint8
const (
	SQLStorage StorageType = iota + 1
	NoSQLStorage
)

type Storageer

type Storageer interface {
	GetStorageType() StorageType
	Find(table string, filter ztype.Map, fn ...func(*CondOptions) error) (ztype.Maps, error)
	First(table string, filter ztype.Map, fn ...func(*CondOptions) error) (ztype.Map, error)
	Pages(table string, page, pagesize int, filter ztype.Map, fn ...func(*CondOptions) error) (ztype.Maps, PageInfo, error)
	Migration(model *Model) Migrationer
	Insert(table string, data ztype.Map) (lastId interface{}, err error)
	InsertMany(table string, data ztype.Maps) (lastIds []interface{}, err error)
	Delete(table string, filter ztype.Map, fn ...func(*CondOptions) error) (int64, error)
	Update(table string, data ztype.Map, filter ztype.Map, fn ...func(*CondOptions) error) (int64, error)
}

func NewSQL

func NewSQL(db *zdb.DB, o ...func(*SQLOptions)) Storageer

type UploadOptions

type UploadOptions struct {
	ConveFilePath func(file, name, dir string) string
	FormName      string
	Dir           string
	AllowTypes    []string
	AllowExts     []string
	MaxSize       uint64
	MaxFiles      int
	SafeDir       bool
}

type ValidTriggerType

type ValidTriggerType uint
const (
	ValidTriggerAll ValidTriggerType = iota
	ValidTriggerCreate
	ValidTriggerUpdate
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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