feat: 升级 samber/do v1 → v2
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package contracts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"git.fsdpf.net/go/condition"
|
||||
"git.fsdpf.net/go/db"
|
||||
"git.fsdpf.net/go/db/exp"
|
||||
"git.fsdpf.net/go/reflux"
|
||||
"git.fsdpf.net/go/req"
|
||||
)
|
||||
|
||||
@@ -12,39 +15,35 @@ type OrmExecute int
|
||||
|
||||
type RelationType string
|
||||
|
||||
type OrderByDirection string
|
||||
|
||||
const (
|
||||
OrmExecute_Query OrmExecute = iota
|
||||
OrmExecute_Show
|
||||
OrmExecute_Store
|
||||
OrmExecute_Destroy
|
||||
OrmQuery OrmExecute = iota
|
||||
OrmShow
|
||||
OrmStore
|
||||
OrmDestroy
|
||||
)
|
||||
|
||||
const (
|
||||
RelationType_HasOne RelationType = "hasOne"
|
||||
RelationType_HasMany RelationType = "hasMany"
|
||||
RelationType_Inner RelationType = "inner"
|
||||
RelationType_Left RelationType = "left"
|
||||
RelationType_Right RelationType = "right"
|
||||
OrmHasOne RelationType = "hasOne"
|
||||
OrmHasMany RelationType = "hasMany"
|
||||
OrmInnerJoin RelationType = "inner"
|
||||
OrmLeftJoin RelationType = "left"
|
||||
OrmRightJoin RelationType = "right"
|
||||
)
|
||||
|
||||
const (
|
||||
OrderByDirection_ASC OrderByDirection = db.ORDER_ASC
|
||||
OrderByDirection_DESC OrderByDirection = db.ORDER_DESC
|
||||
)
|
||||
type ModelDecorator func(Model) Model
|
||||
|
||||
type Orm interface {
|
||||
SetGlobalParams(g req.GlobalParams) Orm
|
||||
SetGlobalParams(g req.UserAccessor) Orm
|
||||
GetModel(params ...string) Model
|
||||
SetRelationModel(m Model) Model
|
||||
SetQueryField(qf req.QueryField) error
|
||||
SetOrderBy(params []OrderBy) error
|
||||
SetCondition(cond *condition.Condition) error
|
||||
SetController(ctr OrmController) error
|
||||
Execute(OrmExecute) (any, error)
|
||||
Clone(tx *db.Transaction) Orm
|
||||
Count() int
|
||||
Controller() reflect.Value
|
||||
Execute(OrmExecute) (reflux.R, error)
|
||||
Clone(tx *db.TxDatabase) Orm
|
||||
Count() int64
|
||||
// Exists() bool
|
||||
}
|
||||
|
||||
@@ -54,7 +53,6 @@ type Relation interface {
|
||||
Type() RelationType
|
||||
SetType(RelationType)
|
||||
SetCondition(*condition.Condition) *condition.Condition
|
||||
SetPrependCondition(*condition.Condition) *condition.Condition
|
||||
GetCondition() *condition.Condition
|
||||
GetRelationResource() string
|
||||
GetRelationField() string
|
||||
@@ -66,8 +64,9 @@ type Join interface {
|
||||
GetCode() string
|
||||
GetResource() req.Resource
|
||||
// GetDependencies(items []ResRelation, dependencies ...string) []string
|
||||
Inject(dbBuilder *db.Builder, m Model)
|
||||
Inject(dbBuilder *db.SelectDataset, m Model)
|
||||
}
|
||||
|
||||
type Model interface {
|
||||
Relation
|
||||
condition.TokenValue
|
||||
@@ -76,28 +75,30 @@ type Model interface {
|
||||
GetPrimaryKey() string
|
||||
GetQueryFieldsStruct(extends ...reflect.StructField) any
|
||||
GetQueryFieldsSliceStruct(fields ...reflect.StructField) any
|
||||
GetAttribute() map[string]any
|
||||
GetResult() reflect.Value
|
||||
GetAttribute() reflux.R
|
||||
SetRelationAttribute(string, reflux.R) error
|
||||
GetResult() reflux.R
|
||||
GetResource() req.Resource
|
||||
QueryBuilder() *db.Builder
|
||||
GetTransaction() *db.Transaction
|
||||
SetQueryField(req.QueryField)
|
||||
SetRelationResult(code string, vItems reflect.Value)
|
||||
GetTransaction() *db.TxDatabase
|
||||
SetQueryField(...req.QueryField)
|
||||
// SetRelationResult(code string, items []reflux.R)
|
||||
GetJoinsCode() []string
|
||||
SetAuthDB(req.ResAuthDB)
|
||||
SetOrderBy(params ...OrderBy) Model
|
||||
SetGroupBy(params ...GroupBy) Model
|
||||
SetJoin(Join) Model
|
||||
SetLimit(int) Model
|
||||
SetOffset(int) Model
|
||||
SetAttribute(data any) Model
|
||||
SetLimit(uint) Model
|
||||
SetOffset(uint) Model
|
||||
// SetAttribute(data any) Model
|
||||
SetPrimaryKey(string) Model
|
||||
SetWithRecursive(QueryWithRecursive) Model
|
||||
DelQueryField(string)
|
||||
SelectDataset() *db.SelectDataset
|
||||
SelectDatasetWithUser(u req.User) *db.SelectDataset
|
||||
Query() error
|
||||
Store() error
|
||||
Destroy() error
|
||||
Count() (int, error)
|
||||
Count() (int64, error)
|
||||
// Exists() (bool, error)
|
||||
}
|
||||
|
||||
@@ -106,18 +107,18 @@ type OrmController interface {
|
||||
}
|
||||
|
||||
type OrderBy interface {
|
||||
ToSql() db.Expression
|
||||
Inject(dbBuilder *db.Builder, m Model)
|
||||
ToSql() exp.OrderedExpression
|
||||
Inject(sd *db.SelectDataset, m Model)
|
||||
}
|
||||
|
||||
type GroupBy interface {
|
||||
ToSql() db.Expression
|
||||
Inject(dbBuilder *db.Builder, m Model)
|
||||
ToSql() exp.ColumnListExpression
|
||||
Inject(sd *db.SelectDataset, m Model)
|
||||
}
|
||||
|
||||
type QueryWithRecursive interface {
|
||||
ToQueryBuilder(*db.Builder, Model) (*db.Builder, any)
|
||||
ToTreeData(any) any
|
||||
ToQueryBuilder(*db.SelectDataset, Model) (*db.SelectDataset, any)
|
||||
ToTreeData([]reflux.R) reflux.R
|
||||
}
|
||||
|
||||
// @title 创建关联模型
|
||||
@@ -130,18 +131,23 @@ type NewOrmRelation func(t RelationType, m Model, rResource, rField, rForeignKey
|
||||
|
||||
type NewOrmJoin func(t RelationType, res req.Resource, alias, rResource, rField, rForeignKey string) Join
|
||||
|
||||
type NewOrmQueryWithRecursive func(pField, cField string, root any, isWithoutCondition bool, depth int) QueryWithRecursive
|
||||
type NewOrmQueryWithRecursive func(pField, cField exp.IdentifierExpression, root any, isWithoutCondition bool, depth uint) QueryWithRecursive
|
||||
|
||||
type NewOrmOrderBy func(sql string, direction OrderByDirection) OrderBy
|
||||
type NewOrmOrderBy func(sql db.Expression, direction exp.SortDirection) OrderBy
|
||||
|
||||
type NewOrmGroupBy func(sql string) GroupBy
|
||||
type NewOrmGroupBy func(db.Expression) GroupBy
|
||||
|
||||
type NewOrmModel func(res req.Resource, code, name string) Model
|
||||
|
||||
type NewOrm func(res req.Resource, tx *db.Transaction) Orm
|
||||
type NewOrm func(res req.Resource, opts ...OrmOption) Orm
|
||||
|
||||
type GetOrmConditions func(categoryUuid string, opts ...condition.Option) *condition.Condition
|
||||
|
||||
type GetOrmOrderBy func(categoryUuid string) []OrderBy
|
||||
|
||||
type GetOrmGroupBy func(categoryUuid string) []GroupBy
|
||||
|
||||
type OrmOption func(Orm)
|
||||
type WithTx func(tx *db.TxDatabase) OrmOption
|
||||
type WithContext func(ctx context.Context) OrmOption
|
||||
type WithUserAccessor func(ua req.UserAccessor) OrmOption
|
||||
|
||||
Reference in New Issue
Block a user