diff --git a/orm.go b/orm.go index 6e7b20e..f10a682 100644 --- a/orm.go +++ b/orm.go @@ -10,7 +10,6 @@ type OrmExecute int type RelationType string -type QueryDataType string type ConditionType string type ConditionOperator string type ConditionTokenType string @@ -60,27 +59,11 @@ const ( 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 ( OrderByDirection_ASC OrderByDirection = db.ORDER_ASC OrderByDirection_DESC OrderByDirection = db.ORDER_DESC ) -const ( - QueryField_IsExpr = 1 << iota - QueryField_IsOmitempty - QueryField_Ignored -) - type Orm interface { SetGlobalParams(g GlobalParams) Orm GetModel(params ...string) Model @@ -88,12 +71,13 @@ type Orm interface { SetQueryField(qf QueryField) error SetOrderBy(params []OrderBy) error SetCondition(cond Condition) error - SetController(ctr reflect.Value) error + SetController(ctr OrmController) error Execute(OrmExecute) (any, error) Clone(tx *db.Transaction) Orm Count() int // Exists() bool } + type Relation interface { Parent() Model AppendTo(Model) @@ -151,6 +135,11 @@ type ModelParam interface { GetGlobalParamsUser() User } +type OrmController interface { + Init() error + AuthDB() ResAuthDB +} + type Condition interface { Type() ConditionType IsEmpty() bool @@ -181,19 +170,6 @@ type ConditionExpr interface { 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 { ToSql() db.Expression Inject(dbBuilder *db.Builder, m Model) diff --git a/resource.go b/resource.go index 9f69630..22ef835 100644 --- a/resource.go +++ b/resource.go @@ -13,6 +13,8 @@ type ResConditionTokenType string type ResConditionOperator string type ResAuthDB int +type QueryDataType string + const ( // 关闭权限过滤 ResAuthOff ResAuthDB = iota @@ -36,6 +38,22 @@ const ( 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 { GetUuid() string GetName() string @@ -76,5 +94,18 @@ type ResField interface { 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)