Documentation ¶
Index ¶
- Constants
- Variables
- func Count[T Filter](m *Schema, filter T, fn ...func(*CondOptions)) (uint64, error)
- func Delete[T filter](m *Schema, filter T, fn ...func(*CondOptions)) (int64, error)
- func DeleteMany[T filter](m *Schema, filter T, fn ...func(*CondOptions)) (int64, error)
- func Find[T filter](m *Schema, filter T, fn ...func(*CondOptions)) (ztype.Maps, error)
- func FindCol[T filter](m *Schema, field string, filter T, fn ...func(*CondOptions)) (ztype.Type, bool, error)
- func FindCols[T filter](m *Schema, field string, filter T, fn ...func(*CondOptions)) (ztype.SliceType, error)
- func FindOne[T filter](m *Schema, filter T, fn ...func(*CondOptions)) (ztype.Map, error)
- func GetEngine[T *zdb.DB](m *Store) T
- func IDKey() string
- func Insert(m *Schema, data ztype.Map, fn ...func(*InsertOptions)) (lastId interface{}, err error)
- func InsertMany(m *Schema, datas ztype.Maps, fn ...func(*InsertOptions)) (lastIds []interface{}, err error)
- func Update[T filter](m *Schema, filter T, data ztype.Map, fn ...func(*CondOptions)) (total int64, err error)
- func UpdateMany[T filter](m *Schema, filter T, data ztype.Map, fn ...func(*CondOptions)) (total int64, err error)
- func VerifiData(data ztype.Map, columns mSchema.Fields, active activeType) (ztype.Map, error)
- type ColumnEnum
- type CondOptions
- type CryptProcess
- type DataTime
- type DealOldColumn
- type Filter
- type InsertOptions
- type Migration
- func (m *Migration) Auto(oldColumn ...DealOldColumn) (err error)
- func (m *Migration) CreateTable(db *zdb.DB) error
- func (m *Migration) GetFields() (ztype.Map, error)
- func (m *Migration) HasTable() bool
- func (m *Migration) Indexs(db *zdb.DB) error
- func (m *Migration) InitValue(first bool) error
- func (m *Migration) UpdateTable(db *zdb.DB, oldColumn ...DealOldColumn) error
- type Migrationer
- type Module
- func (m *Module) GetModel(name string) (*Store, bool)
- func (m *Module) GetSchema(name string) (*Schema, bool)
- func (m *Module) MustGetModel(name string) *Store
- func (m *Module) MustGetSchema(name string) *Schema
- func (m *Module) Name() string
- func (m *Module) Schemas() *Schemas
- func (m *Module) Stores() *Stores
- func (m *Module) String() string
- type Options
- type PageData
- type PageInfo
- type SQL
- func (s *SQL) Delete(table string, fields []string, filter ztype.Map, fn ...func(*CondOptions)) (int64, error)
- func (s *SQL) Find(table string, fields []string, filter ztype.Map, fn ...func(*CondOptions)) (ztype.Maps, error)
- func (s *SQL) First(table string, fields []string, filter ztype.Map, fn ...func(*CondOptions)) (ztype.Map, error)
- func (s *SQL) GetDB() *zdb.DB
- func (s *SQL) GetOptions() ztype.Map
- func (s *SQL) GetStorageType() StorageType
- func (s *SQL) Insert(table string, fields []string, data ztype.Map, fn ...func(*InsertOptions)) (lastId interface{}, err error)
- func (s *SQL) InsertMany(table string, fields []string, data ztype.Maps, fn ...func(*InsertOptions)) (lastIds []interface{}, err error)
- func (s *SQL) Migration(model *Schema) Migrationer
- func (s *SQL) Pages(table string, fields []string, page, pagesize int, filter ztype.Map, ...) (ztype.Maps, PageInfo, error)
- func (s *SQL) Transaction(run func(s *SQL) error) (err error)
- func (s *SQL) Update(table string, fields []string, data ztype.Map, filter ztype.Map, ...) (int64, error)
- type SQLOptions
- type Schema
- func (m *Schema) DI() zdi.Injector
- func (m *Schema) DeCrypt(row ztype.Map) (success bool)
- func (m *Schema) DeCryptID(nid string) (id string, err error)
- func (m *Schema) EnCrypt(row *ztype.Map) (err error)
- func (m *Schema) EnCryptID(id string) (nid string, err error)
- func (m *Schema) GetAfterProcess(p []string) (fn []afterProcess, err error)
- func (m *Schema) GetAlias() string
- func (m *Schema) GetBeforeProcess(p []string) (fn []beforeProcess, err error)
- func (m *Schema) GetComment() string
- func (m *Schema) GetCryptProcess(cryptName string) (fn CryptProcess, err error)
- func (m *Schema) GetDefine() schema.Schema
- func (m *Schema) GetExtend() ztype.Map
- func (m *Schema) GetField(name string) (mSchema.Field, bool)
- func (m *Schema) GetFields(exclude ...string) []string
- func (m *Schema) GetModelFields() mSchema.Fields
- func (m *Schema) GetName() string
- func (m *Schema) GetTableName() string
- func (m *Schema) GetViewFields(view string) []string
- func (m *Schema) GetViews() ztype.Map
- func (m *Schema) MarshalJSON() ([]byte, error)
- func (m *Schema) Migration() Migrationer
- func (m *Schema) Model() *Store
- func (m *Schema) ParseLables(items ztype.Maps) ztype.Maps
- type SchemaOptions
- type Schemas
- func (ss *Schemas) BatchReg(models map[string]schema.Schema, force bool) error
- func (ss *Schemas) ForEach(fn func(key string, m *Schema) bool)
- func (ss *Schemas) Get(alias string) (*Schema, bool)
- func (ss *Schemas) Models() *Stores
- func (ss *Schemas) MustGet(alias string) *Schema
- func (ss *Schemas) Reg(name string, data schema.Schema, force bool) (*Schema, error)
- func (ss *Schemas) Storage() Storageer
- func (ss *Schemas) String() string
- type StorageJoin
- type StorageModelOptions
- type StorageType
- type Storageer
- type Store
- func (o *Store) Count(filter Filter, fn ...func(*CondOptions)) (uint64, error)
- func (o *Store) Delete(filter Filter, fn ...func(*CondOptions)) (total int64, err error)
- func (o *Store) DeleteByID(id any, fn ...func(*CondOptions)) (total int64, err error)
- func (o *Store) DeleteMany(filter Filter, fn ...func(*CondOptions)) (total int64, err error)
- func (o *Store) Exists(filter Filter, fn ...func(*CondOptions)) (bool, error)
- func (o *Store) Find(filter Filter, fn ...func(*CondOptions)) (ztype.Maps, error)
- func (o *Store) FindCols(field string, filter Filter) (ztype.SliceType, error)
- func (o *Store) FindOne(filter Filter, fn ...func(*CondOptions)) (ztype.Map, error)
- func (o *Store) FindOneByID(id any, fn ...func(*CondOptions)) (ztype.Map, error)
- func (o *Store) Insert(data ztype.Map, fn ...func(*InsertOptions)) (lastId interface{}, err error)
- func (o *Store) InsertMany(data ztype.Maps, fn ...func(*InsertOptions)) (lastId interface{}, err error)
- func (o *Store) Pages(page, pagesize int, filter Filter, fn ...func(*CondOptions)) (*PageData, error)
- func (o *Store) Schema(Storage ...Storageer) *Schema
- func (o *Store) Update(filter Filter, data ztype.Map, fn ...func(*CondOptions)) (total int64, err error)
- func (o *Store) UpdateByID(id any, data ztype.Map, fn ...func(*CondOptions)) (total int64, err error)
- func (o *Store) UpdateMany(filter Filter, data ztype.Map, fn ...func(*CondOptions)) (total int64, err error)
- type Stores
- type ValidTriggerType
Constants ¶
View Source
const ( CreatedAtKey = "created_at" // CreatedByKey = "created_by" UpdatedAtKey = "updated_at" DeletedAtKey = "deleted_at" )
Variables ¶
View Source
var Common = &common{}
View Source
var InsideOption = &inside{}
Functions ¶
func DeleteMany ¶
func DeleteMany[T filter](m *Schema, filter T, fn ...func(*CondOptions)) (int64, error)
func FindOne ¶
func FindOne[T filter](m *Schema, filter T, fn ...func(*CondOptions)) (ztype.Map, error)
func Insert ¶
func Insert(m *Schema, data ztype.Map, fn ...func(*InsertOptions)) (lastId interface{}, err error)
func InsertMany ¶
func InsertMany(m *Schema, datas ztype.Maps, fn ...func(*InsertOptions)) (lastIds []interface{}, err error)
func UpdateMany ¶
Types ¶
type ColumnEnum ¶
type CondOptions ¶
type CryptProcess ¶
type DealOldColumn ¶
type DealOldColumn uint8
type InsertOptions ¶
type InsertOptions struct {
Options string
}
type Migration ¶
func (*Migration) Auto ¶
func (m *Migration) Auto(oldColumn ...DealOldColumn) (err error)
func (*Migration) UpdateTable ¶
func (m *Migration) UpdateTable(db *zdb.DB, oldColumn ...DealOldColumn) error
type Migrationer ¶
type Module ¶
type Module struct { service.ModuleLifeCycle Options Options // contains filtered or unexported fields }
func (*Module) MustGetModel ¶
func (*Module) MustGetSchema ¶
type Options ¶
type Options struct { // SetStorageer 手动设置数据库 SetStorageer func() (Storageer, error) // SetAlternateModels 动态设置关联表 SetAlternateModels func() ([]*Store, error) // SchemaMiddleware 自定义 schema 中间件 SchemaMiddleware func() []znet.Handler // Prefix 模型前缀 Prefix string // SchemaDir 模型定义目录 SchemaDir string // SchemaApi schema api 路径 SchemaApi string // Schemas 定义模型 Schemas schema.Schemas // SchemaOptions 模型选项 SchemaOptions }
type PageData ¶
type PageData struct { Items ztype.Maps `json:"items"` Page PageInfo `json:"page"` // contains filtered or unexported fields }
type SQL ¶
type SQL struct { Options SQLOptions // contains filtered or unexported fields }
func (*SQL) GetOptions ¶
func (*SQL) GetStorageType ¶
func (s *SQL) GetStorageType() StorageType
func (*SQL) InsertMany ¶
func (*SQL) Migration ¶
func (s *SQL) Migration(model *Schema) Migrationer
type SQLOptions ¶
type SQLOptions struct {
// contains filtered or unexported fields
}
type Schema ¶
type Schema struct { Storage Storageer Hashid *hashid.HashID `json:"-"` JSONPath string JSON []byte StorageType StorageType // contains filtered or unexported fields }
func (*Schema) GetAfterProcess ¶
func (*Schema) GetBeforeProcess ¶
func (*Schema) GetComment ¶
func (*Schema) GetCryptProcess ¶
func (m *Schema) GetCryptProcess(cryptName string) (fn CryptProcess, err error)
func (*Schema) GetModelFields ¶
func (*Schema) GetTableName ¶
func (*Schema) GetViewFields ¶
func (*Schema) MarshalJSON ¶
func (*Schema) Migration ¶
func (m *Schema) Migration() Migrationer
type SchemaOptions ¶
type SchemaOptions struct { // DisabledMigrator 禁用自动迁移 DisabledMigrator bool `z:"disabled_migrator,omitempty"` // SoftDeletes 开启软删除 SoftDeletes bool `z:"soft_deletes,omitempty"` // Timestamps 注入创建/更新时间 Timestamps bool `z:"timestamps,omitempty"` // CryptID 加密 ID CryptID bool `z:"crypt_id,omitempty"` }
type Schemas ¶
type Schemas struct { SchemaOption SchemaOptions // contains filtered or unexported fields }
func NewSchemas ¶
func NewSchemas(di zdi.Injector, s Storageer, o SchemaOptions) *Schemas
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 )
func (StorageType) String ¶
func (s StorageType) String() string
type Storageer ¶
type Storageer interface { GetStorageType() StorageType GetOptions() ztype.Map Transaction(run func(s *SQL) error) (err error) Find(table string, fields []string, filter ztype.Map, fn ...func(*CondOptions)) (ztype.Maps, error) First(table string, fields []string, filter ztype.Map, fn ...func(*CondOptions)) (ztype.Map, error) Pages(table string, fields []string, page, pagesize int, filter ztype.Map, fn ...func(*CondOptions)) (ztype.Maps, PageInfo, error) Migration(model *Schema) Migrationer Insert(table string, fields []string, data ztype.Map, fn ...func(*InsertOptions)) (lastId interface{}, err error) InsertMany(table string, fields []string, data ztype.Maps, fn ...func(*InsertOptions)) (lastIds []interface{}, err error) Delete(table string, fields []string, filter ztype.Map, fn ...func(*CondOptions)) (int64, error) Update(table string, fields []string, data ztype.Map, filter ztype.Map, fn ...func(*CondOptions)) (int64, error) }
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) Count ¶
func (o *Store) Count(filter Filter, fn ...func(*CondOptions)) (uint64, error)
Count 统计数量
func (*Store) Delete ¶
func (o *Store) Delete(filter Filter, fn ...func(*CondOptions)) (total int64, err error)
Delete 删除数据
func (*Store) DeleteByID ¶
func (o *Store) DeleteByID(id any, fn ...func(*CondOptions)) (total int64, err error)
DeleteByID 通过ID删除数据
func (*Store) DeleteMany ¶
func (o *Store) DeleteMany(filter Filter, fn ...func(*CondOptions)) (total int64, err error)
DeleteMany 删除多条数据
func (*Store) Exists ¶
func (o *Store) Exists(filter Filter, fn ...func(*CondOptions)) (bool, error)
Exists 数据是否存在
func (*Store) FindOneByID ¶
FindOneByID 通过ID查询
func (*Store) Insert ¶
func (o *Store) Insert(data ztype.Map, fn ...func(*InsertOptions)) (lastId interface{}, err error)
Insert 插入数据
func (*Store) InsertMany ¶
func (o *Store) InsertMany(data ztype.Maps, fn ...func(*InsertOptions)) (lastId interface{}, err error)
InsertMany 批量插入数据
func (*Store) Pages ¶
func (o *Store) Pages(page, pagesize int, filter Filter, fn ...func(*CondOptions)) (*PageData, error)
Pages 分页查询
func (*Store) Update ¶
func (o *Store) Update(filter Filter, data ztype.Map, fn ...func(*CondOptions)) (total int64, err error)
Update 更新数据
func (*Store) UpdateByID ¶
func (o *Store) UpdateByID(id any, data ztype.Map, fn ...func(*CondOptions)) (total int64, err error)
UpdateByID 通过ID更新
func (*Store) UpdateMany ¶
func (o *Store) UpdateMany(filter Filter, data ztype.Map, fn ...func(*CondOptions)) (total int64, err error)
UpdateMany 更新多条数据
type ValidTriggerType ¶
type ValidTriggerType uint
const ( ValidTriggerAll ValidTriggerType = iota ValidTriggerCreate ValidTriggerUpdate )
Source Files ¶
Click to show internal directories.
Click to hide internal directories.