[feat] 分离 orm 中查询字段部分到 resource
This commit is contained in:
parent
b6347d7963
commit
14b6334887
38
orm.go
38
orm.go
@ -10,7 +10,6 @@ type OrmExecute int
|
|||||||
|
|
||||||
type RelationType string
|
type RelationType string
|
||||||
|
|
||||||
type QueryDataType string
|
|
||||||
type ConditionType string
|
type ConditionType string
|
||||||
type ConditionOperator string
|
type ConditionOperator string
|
||||||
type ConditionTokenType string
|
type ConditionTokenType string
|
||||||
@ -60,27 +59,11 @@ const (
|
|||||||
ConditionOperator_NOT_REGEXP ConditionOperator = "NOT REGEXP"
|
ConditionOperator_NOT_REGEXP ConditionOperator = "NOT REGEXP"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
QueryDataType_Number QueryDataType = "number"
|
|
||||||
QueryDataType_Integer QueryDataType = "integer"
|
|
||||||
QueryDataType_Float QueryDataType = "float"
|
|
||||||
QueryDataType_String QueryDataType = "string"
|
|
||||||
QueryDataType_Bool QueryDataType = "bool"
|
|
||||||
QueryDataType_Array QueryDataType = "array"
|
|
||||||
QueryDataType_Json QueryDataType = "json"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
OrderByDirection_ASC OrderByDirection = db.ORDER_ASC
|
OrderByDirection_ASC OrderByDirection = db.ORDER_ASC
|
||||||
OrderByDirection_DESC OrderByDirection = db.ORDER_DESC
|
OrderByDirection_DESC OrderByDirection = db.ORDER_DESC
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
QueryField_IsExpr = 1 << iota
|
|
||||||
QueryField_IsOmitempty
|
|
||||||
QueryField_Ignored
|
|
||||||
)
|
|
||||||
|
|
||||||
type Orm interface {
|
type Orm interface {
|
||||||
SetGlobalParams(g GlobalParams) Orm
|
SetGlobalParams(g GlobalParams) Orm
|
||||||
GetModel(params ...string) Model
|
GetModel(params ...string) Model
|
||||||
@ -88,12 +71,13 @@ type Orm interface {
|
|||||||
SetQueryField(qf QueryField) error
|
SetQueryField(qf QueryField) error
|
||||||
SetOrderBy(params []OrderBy) error
|
SetOrderBy(params []OrderBy) error
|
||||||
SetCondition(cond Condition) error
|
SetCondition(cond Condition) error
|
||||||
SetController(ctr reflect.Value) error
|
SetController(ctr OrmController) error
|
||||||
Execute(OrmExecute) (any, error)
|
Execute(OrmExecute) (any, error)
|
||||||
Clone(tx *db.Transaction) Orm
|
Clone(tx *db.Transaction) Orm
|
||||||
Count() int
|
Count() int
|
||||||
// Exists() bool
|
// Exists() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Relation interface {
|
type Relation interface {
|
||||||
Parent() Model
|
Parent() Model
|
||||||
AppendTo(Model)
|
AppendTo(Model)
|
||||||
@ -151,6 +135,11 @@ type ModelParam interface {
|
|||||||
GetGlobalParamsUser() User
|
GetGlobalParamsUser() User
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OrmController interface {
|
||||||
|
Init() error
|
||||||
|
AuthDB() ResAuthDB
|
||||||
|
}
|
||||||
|
|
||||||
type Condition interface {
|
type Condition interface {
|
||||||
Type() ConditionType
|
Type() ConditionType
|
||||||
IsEmpty() bool
|
IsEmpty() bool
|
||||||
@ -181,19 +170,6 @@ type ConditionExpr interface {
|
|||||||
IsIgnoreEmptyParma(ModelParam) bool
|
IsIgnoreEmptyParma(ModelParam) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryField interface {
|
|
||||||
ResField
|
|
||||||
Type() QueryDataType
|
|
||||||
Alias() string
|
|
||||||
GetCodeOrAlias() string
|
|
||||||
IsExpr() bool
|
|
||||||
IsOmitempty() bool
|
|
||||||
Ignored() bool
|
|
||||||
SetOptions(int) QueryField
|
|
||||||
ToSql() db.Expression
|
|
||||||
ToStructField(tags ...string) reflect.StructField
|
|
||||||
}
|
|
||||||
|
|
||||||
type OrderBy interface {
|
type OrderBy interface {
|
||||||
ToSql() db.Expression
|
ToSql() db.Expression
|
||||||
Inject(dbBuilder *db.Builder, m Model)
|
Inject(dbBuilder *db.Builder, m Model)
|
||||||
|
31
resource.go
31
resource.go
@ -13,6 +13,8 @@ type ResConditionTokenType string
|
|||||||
type ResConditionOperator string
|
type ResConditionOperator string
|
||||||
type ResAuthDB int
|
type ResAuthDB int
|
||||||
|
|
||||||
|
type QueryDataType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// 关闭权限过滤
|
// 关闭权限过滤
|
||||||
ResAuthOff ResAuthDB = iota
|
ResAuthOff ResAuthDB = iota
|
||||||
@ -36,6 +38,22 @@ const (
|
|||||||
ResDataType_Datetime ResDataType = "dateTime"
|
ResDataType_Datetime ResDataType = "dateTime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
QueryDataType_Number QueryDataType = "number"
|
||||||
|
QueryDataType_Integer QueryDataType = "integer"
|
||||||
|
QueryDataType_Float QueryDataType = "float"
|
||||||
|
QueryDataType_String QueryDataType = "string"
|
||||||
|
QueryDataType_Bool QueryDataType = "bool"
|
||||||
|
QueryDataType_Array QueryDataType = "array"
|
||||||
|
QueryDataType_Json QueryDataType = "json"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
QueryField_IsExpr = 1 << iota
|
||||||
|
QueryField_IsOmitempty
|
||||||
|
QueryField_Ignored
|
||||||
|
)
|
||||||
|
|
||||||
type Resource interface {
|
type Resource interface {
|
||||||
GetUuid() string
|
GetUuid() string
|
||||||
GetName() string
|
GetName() string
|
||||||
@ -76,5 +94,18 @@ type ResField interface {
|
|||||||
ToQueryField(t QueryDataType, alias string, options int) QueryField
|
ToQueryField(t QueryDataType, alias string, options int) QueryField
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QueryField interface {
|
||||||
|
ResField
|
||||||
|
Type() QueryDataType
|
||||||
|
Alias() string
|
||||||
|
GetCodeOrAlias() string
|
||||||
|
IsExpr() bool
|
||||||
|
IsOmitempty() bool
|
||||||
|
Ignored() bool
|
||||||
|
SetOptions(int) QueryField
|
||||||
|
ToSql() db.Expression
|
||||||
|
ToStructField(tags ...string) reflect.StructField
|
||||||
|
}
|
||||||
|
|
||||||
// 资源
|
// 资源
|
||||||
type GetResource func(code string) (Resource, bool)
|
type GetResource func(code string) (Resource, bool)
|
||||||
|
Loading…
Reference in New Issue
Block a user