From 14b633488760987c97886cb68f03208cf2028f4d Mon Sep 17 00:00:00 2001 From: what Date: Mon, 6 May 2024 18:00:12 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E5=88=86=E7=A6=BB=20orm=20=E4=B8=AD?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=AD=97=E6=AE=B5=E9=83=A8=E5=88=86=E5=88=B0?= =?UTF-8?q?=20resource?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- orm.go | 38 +++++++------------------------------- resource.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 31 deletions(-) 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)