contracts/resource.go

114 lines
2.5 KiB
Go

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
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"
)
type Resource interface {
GetUuid() string
GetName() string
GetCode() string
GetPrimarykey() string
GetFields() []ResField
GetField(string) (ResField, bool)
HasField(string) bool
BeginTransaction() (*db.Transaction, error)
GetDB() *db.Builder
GetTable() db.Expression
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, roles ...string)
GetRolesCondition(u User)
// 是否虚拟资源
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
}
type ResRelation interface{}
type ResJoin interface {
ResRelation
}
type ResQueryField interface {
ResField
IsExpr() bool
ToSql() db.Expression
}
type ResCondition interface {
// 是否空条件
IsEmpty() bool
// 条件是否恒成立
IsRight() bool
// to sql 表达式
ToSql() db.Expression
}
type ResConditionExpr interface {
// 条件是否恒成立
IsRight() bool
// to sql 表达式
ToSql() db.Expression
GetTokenName() string
GetTokenValue() any
GetTokenSqlValue() string
GetTokenType() ResConditionTokenType
}
// 资源
type GetResource func(code string) (Resource, bool)