[feat] 统一 orm 入口
This commit is contained in:
parent
14b6334887
commit
6b87809781
@ -1,7 +1,5 @@
|
|||||||
package base
|
package base
|
||||||
|
|
||||||
import "git.fsdpf.net/go/contracts"
|
|
||||||
|
|
||||||
type ResCondition struct {
|
type ResCondition struct {
|
||||||
Id int `db:"id"`
|
Id int `db:"id"`
|
||||||
Pid int `db:"pid"`
|
Pid int `db:"pid"`
|
||||||
@ -38,5 +36,3 @@ type ResWhereExpr struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetResConditions func(categoryUuid string) []ResCondition
|
type GetResConditions func(categoryUuid string) []ResCondition
|
||||||
|
|
||||||
type GetOrmConditionByRes func(categoryUuid string, describe string) contracts.Condition
|
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
|
||||||
"git.fsdpf.net/go/contracts"
|
"git.fsdpf.net/go/contracts"
|
||||||
"git.fsdpf.net/go/contracts/helper"
|
|
||||||
"git.fsdpf.net/go/contracts/support"
|
"git.fsdpf.net/go/contracts/support"
|
||||||
"git.fsdpf.net/go/db"
|
"git.fsdpf.net/go/db"
|
||||||
)
|
)
|
||||||
@ -218,14 +217,14 @@ func (this Resource) WithRolesCondition(b *db.Builder, t string, u contracts.Use
|
|||||||
isFullRight := false
|
isFullRight := false
|
||||||
isFullNot := false
|
isFullNot := false
|
||||||
|
|
||||||
NewOrm := do.MustInvoke[helper.NewOrm](this.container)
|
NewOrm := do.MustInvoke[contracts.NewOrm](this.container)
|
||||||
NewOrmModel := do.MustInvoke[helper.NewOrmModel](this.container)
|
NewOrmModel := do.MustInvoke[contracts.NewOrmModel](this.container)
|
||||||
NewOrmJoin := do.MustInvoke[helper.NewOrmJoin](this.container)
|
NewOrmJoin := do.MustInvoke[contracts.NewOrmJoin](this.container)
|
||||||
|
|
||||||
GetResRelationResource := do.MustInvoke[GetResRelationResource](this.container)
|
GetResRelationResource := do.MustInvoke[GetResRelationResource](this.container)
|
||||||
GetResRelations := do.MustInvoke[GetResRelations](this.container)
|
GetResRelations := do.MustInvoke[GetResRelations](this.container)
|
||||||
GetResource := do.MustInvoke[contracts.GetResource](this.container)
|
GetResource := do.MustInvoke[contracts.GetResource](this.container)
|
||||||
GetOrmConditionByRes := do.MustInvoke[GetOrmConditionByRes](this.container)
|
GetOrmConditionByRes := do.MustInvoke[contracts.GetOrmConditionByRes](this.container)
|
||||||
|
|
||||||
items := do.MustInvoke[GetResRoles](this.container)(this.GetUuid(), u.Roles()...)
|
items := do.MustInvoke[GetResRoles](this.container)(this.GetUuid(), u.Roles()...)
|
||||||
|
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
package helper
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.fsdpf.net/go/contracts"
|
|
||||||
"git.fsdpf.net/go/db"
|
|
||||||
)
|
|
||||||
|
|
||||||
// @title 创建关联模型
|
|
||||||
// @param t 关联类型
|
|
||||||
// @param m 关联模型
|
|
||||||
// @param rResource 链接父模型
|
|
||||||
// @param rField 连接父模型字段, 如 xx_id
|
|
||||||
// @param rForeignKey 关联外键, 如 id
|
|
||||||
type NewOrmRelation func(t contracts.RelationType, m contracts.Model, rResource, rField, rForeignKey string) contracts.Model
|
|
||||||
|
|
||||||
type NewOrmJoin func(t contracts.RelationType, res contracts.Resource, alias, rResource, rField, rForeignKey string) contracts.Join
|
|
||||||
|
|
||||||
type NewOrmCondition func(typ contracts.ConditionType, describe string) contracts.Condition
|
|
||||||
|
|
||||||
type NewOrmConditionExpr func(rResource, rField, token string, operator contracts.ConditionOperator, tType contracts.ConditionTokenType, ignoreEmptyParma bool) contracts.ConditionExpr
|
|
||||||
|
|
||||||
type NewOrmConditionFuncExpr func(rResource, rField, token string, operator contracts.ConditionOperator, tType contracts.ConditionTokenType, ignoreEmptyParma bool, fn, fnParam string) contracts.ConditionExpr
|
|
||||||
|
|
||||||
type NewOrmQueryWithRecursive func(pField, cField string, root any, isWithoutCondition bool, depth int) contracts.QueryWithRecursive
|
|
||||||
|
|
||||||
type NewOrmOrderBy func(sql string, direction contracts.OrderByDirection) contracts.OrderBy
|
|
||||||
|
|
||||||
type NewOrmGroupBy func(sql string) contracts.GroupBy
|
|
||||||
|
|
||||||
type NewOrmModel func(res contracts.Resource, code, name string) contracts.Model
|
|
||||||
|
|
||||||
type NewOrm func(res contracts.Resource, tx *db.Transaction) contracts.Orm
|
|
28
orm.go
28
orm.go
@ -184,3 +184,31 @@ type QueryWithRecursive interface {
|
|||||||
ToQueryBuilder(*db.Builder, Model) (*db.Builder, any)
|
ToQueryBuilder(*db.Builder, Model) (*db.Builder, any)
|
||||||
ToTreeData(any) any
|
ToTreeData(any) any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @title 创建关联模型
|
||||||
|
// @param t 关联类型
|
||||||
|
// @param m 关联模型
|
||||||
|
// @param rResource 链接父模型
|
||||||
|
// @param rField 连接父模型字段, 如 xx_id
|
||||||
|
// @param rForeignKey 关联外键, 如 id
|
||||||
|
type NewOrmRelation func(t RelationType, m Model, rResource, rField, rForeignKey string) Model
|
||||||
|
|
||||||
|
type NewOrmJoin func(t RelationType, res Resource, alias, rResource, rField, rForeignKey string) Join
|
||||||
|
|
||||||
|
type NewOrmCondition func(typ ConditionType, describe string) Condition
|
||||||
|
|
||||||
|
type NewOrmConditionExpr func(rResource, rField, token string, operator ConditionOperator, tType ConditionTokenType, ignoreEmptyParma bool) ConditionExpr
|
||||||
|
|
||||||
|
type NewOrmConditionFuncExpr func(rResource, rField, token string, operator ConditionOperator, tType ConditionTokenType, ignoreEmptyParma bool, fn, fnParam string) ConditionExpr
|
||||||
|
|
||||||
|
type NewOrmQueryWithRecursive func(pField, cField string, root any, isWithoutCondition bool, depth int) QueryWithRecursive
|
||||||
|
|
||||||
|
type NewOrmOrderBy func(sql string, direction OrderByDirection) OrderBy
|
||||||
|
|
||||||
|
type NewOrmGroupBy func(sql string) GroupBy
|
||||||
|
|
||||||
|
type NewOrmModel func(res Resource, code, name string) Model
|
||||||
|
|
||||||
|
type NewOrm func(res Resource, tx *db.Transaction) Orm
|
||||||
|
|
||||||
|
type GetOrmConditionByRes func(categoryUuid string, describe string) Condition
|
||||||
|
Loading…
Reference in New Issue
Block a user