package contracts import ( "reflect" "git.fsdpf.net/go/db" "git.fsdpf.net/go/db/schema" ) type ResDataType string type ResConditionType string type ResConditionTokenType string type ResConditionOperator string type ResAuthDB int type QueryDataType string const ( // 关闭权限过滤 ResAuthOff ResAuthDB = iota // 开启权限过滤, 不包括关联资源 ResAuthOn // 开启权限过滤, 包括关联资源 ResAuthAll ) const ( ResDataType_String ResDataType = "string" ResDataType_Text ResDataType = "text" ResDataType_Integer ResDataType = "integer" ResDataType_SmallInteger ResDataType = "smallInteger" ResDataType_Decimal ResDataType = "decimal" ResDataType_Boolean ResDataType = "boolean" ResDataType_Json ResDataType = "json" ResDataType_Enum ResDataType = "enum" ResDataType_Timestamp ResDataType = "timestamp" ResDataType_Date ResDataType = "date" 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 GetCode() string GetPrimarykey() string GetFields() []ResField GetField(string) (ResField, bool) HasField(string) bool BeginTransaction() (*db.Transaction, error) GetTable() db.Expression GetDBConn() *db.Connection GetDBBuilder() *db.Builder GetDBTable(params ...any) *db.Builder GetAuthDBTable(u User, params ...any) *db.Builder GetStruct(extends ...reflect.StructField) any GetSliceStruct(extends ...reflect.StructField) any WithRolesCondition(b *db.Builder, t string, u User) error // 是否虚拟资源 IsVirtual() bool // 是否系统资源 IsSystem() bool } type ResField interface { GetName() string GetCode() string GetCodeResource() string GetDataType() ResDataType GetQueryDataType() QueryDataType GetRawDefault(driver string) db.Expression ToStructField(tags ...string) reflect.StructField ToValue(any) any ToBlueprint(table *schema.Blueprint) *schema.ColumnDefinition 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)