81 lines
2.0 KiB
Go
81 lines
2.0 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)
|
|
|
|
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 GetResource func(code string) (Resource, bool)
|