187 lines
4.7 KiB
Go
187 lines
4.7 KiB
Go
package contracts
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"git.fsdpf.net/go/db"
|
|
)
|
|
|
|
type OrmExecute int
|
|
|
|
type RelationType string
|
|
|
|
type ConditionType string
|
|
type ConditionOperator string
|
|
type ConditionTokenType string
|
|
type OrderByDirection string
|
|
|
|
const (
|
|
OrmExecute_Query OrmExecute = iota
|
|
OrmExecute_Show
|
|
OrmExecute_Store
|
|
OrmExecute_Destroy
|
|
)
|
|
|
|
const (
|
|
RelationType_HasOne RelationType = "hasOne"
|
|
RelationType_HasMany RelationType = "hasMany"
|
|
RelationType_Inner RelationType = "inner"
|
|
RelationType_Left RelationType = "left"
|
|
RelationType_Right RelationType = "right"
|
|
)
|
|
|
|
const (
|
|
ConditionType_OR ConditionType = "OR"
|
|
ConditionType_AND ConditionType = "AND"
|
|
)
|
|
|
|
const (
|
|
ConditionTokenType_SQL ConditionTokenType = "sql"
|
|
ConditionTokenType_FUNC ConditionTokenType = "func"
|
|
ConditionTokenType_PARAM ConditionTokenType = "param"
|
|
ConditionTokenType_STRING ConditionTokenType = "string"
|
|
)
|
|
|
|
const (
|
|
ConditionOperator_IS_NULL ConditionOperator = "IS NULL"
|
|
ConditionOperator_IS_NOT_NULL ConditionOperator = "IS NOT NULL"
|
|
ConditionOperator_EQ ConditionOperator = "="
|
|
ConditionOperator_NE ConditionOperator = "!="
|
|
ConditionOperator_GT ConditionOperator = ">"
|
|
ConditionOperator_GE ConditionOperator = ">="
|
|
ConditionOperator_LT ConditionOperator = "<"
|
|
ConditionOperator_LE ConditionOperator = "<="
|
|
ConditionOperator_LIKE ConditionOperator = "LIKE"
|
|
ConditionOperator_NOT_LIKE ConditionOperator = "NOT LIKE"
|
|
ConditionOperator_IN ConditionOperator = "IN"
|
|
ConditionOperator_NOT_IN ConditionOperator = "NOT IN"
|
|
ConditionOperator_REGEXP ConditionOperator = "REGEXP"
|
|
ConditionOperator_NOT_REGEXP ConditionOperator = "NOT REGEXP"
|
|
)
|
|
|
|
const (
|
|
OrderByDirection_ASC OrderByDirection = db.ORDER_ASC
|
|
OrderByDirection_DESC OrderByDirection = db.ORDER_DESC
|
|
)
|
|
|
|
type Orm interface {
|
|
SetGlobalParams(g GlobalParams) Orm
|
|
GetModel(params ...string) Model
|
|
SetRelationModel(m Model) Model
|
|
SetQueryField(qf QueryField) error
|
|
SetOrderBy(params []OrderBy) error
|
|
SetCondition(cond Condition) 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)
|
|
Type() RelationType
|
|
SetType(RelationType)
|
|
SetCondition(Condition) Condition
|
|
SetPrependCondition(Condition) Condition
|
|
GetCondition() Condition
|
|
GetRelationResource() string
|
|
GetRelationField() string
|
|
GetRelationForeignKey() string
|
|
}
|
|
|
|
type Join interface {
|
|
Relation
|
|
GetCode() string
|
|
GetResource() Resource
|
|
// GetDependencies(items []ResRelation, dependencies ...string) []string
|
|
Inject(dbBuilder *db.Builder, m Model)
|
|
}
|
|
type Model interface {
|
|
Relation
|
|
ModelParam
|
|
GetCode() string
|
|
GetPrimaryKey() string
|
|
GetQueryFieldsStruct(extends ...reflect.StructField) any
|
|
GetQueryFieldsSliceStruct(fields ...reflect.StructField) any
|
|
GetAttribute() map[string]any
|
|
GetResult() reflect.Value
|
|
GetResource() Resource
|
|
QueryBuilder() *db.Builder
|
|
GetTransaction() *db.Transaction
|
|
SetQueryField(QueryField)
|
|
SetRelationResult(code string, vItems reflect.Value)
|
|
GetJoinsCode() []string
|
|
SetAuthDB(ResAuthDB)
|
|
SetOrderBy(params ...OrderBy) Model
|
|
SetGroupBy(params ...GroupBy) Model
|
|
SetJoin(Join) Model
|
|
SetLimit(int) Model
|
|
SetOffset(int) Model
|
|
SetAttribute(data any) Model
|
|
SetPrimaryKey(string) Model
|
|
SetWithRecursive(QueryWithRecursive) Model
|
|
DelQueryField(string)
|
|
Query() error
|
|
Store() error
|
|
Destroy() error
|
|
Count() (int, error)
|
|
// Exists() (bool, error)
|
|
}
|
|
|
|
type ModelParam interface {
|
|
GetParam(k string) GlobalParams
|
|
GetGlobalParamsUser() User
|
|
}
|
|
|
|
type OrmController interface {
|
|
Init() error
|
|
AuthDB() ResAuthDB
|
|
}
|
|
|
|
type Condition interface {
|
|
Type() ConditionType
|
|
IsEmpty() bool
|
|
IsNotEmpty() bool
|
|
IsAlwaysRight() bool
|
|
ToSql(ModelParam) db.Expression
|
|
AppendTo(Condition)
|
|
SetExpr(ConditionExpr) Condition
|
|
SetCondition(Condition) Condition
|
|
SetMatchPrefix(string) Condition
|
|
GetFields(operator ConditionOperator, types ...ConditionTokenType) map[string]string
|
|
GetFieldsValue(m ModelParam, isWithResource bool) map[string]any
|
|
}
|
|
|
|
type ConditionExpr interface {
|
|
GetField() string
|
|
GetFieldResource() string
|
|
GetOperator() ConditionOperator
|
|
|
|
SetMatchPrefix(string) ConditionExpr
|
|
|
|
AppendTo(Condition)
|
|
ToSql(m ModelParam) db.Expression
|
|
GetTokenName() string
|
|
GetTokenType() ConditionTokenType
|
|
GetTokenValue(ModelParam) any
|
|
GetTokenSqlValue(ModelParam) string
|
|
IsIgnoreEmptyParma(ModelParam) bool
|
|
}
|
|
|
|
type OrderBy interface {
|
|
ToSql() db.Expression
|
|
Inject(dbBuilder *db.Builder, m Model)
|
|
}
|
|
|
|
type GroupBy interface {
|
|
ToSql() db.Expression
|
|
Inject(dbBuilder *db.Builder, m Model)
|
|
}
|
|
|
|
type QueryWithRecursive interface {
|
|
ToQueryBuilder(*db.Builder, Model) (*db.Builder, any)
|
|
ToTreeData(any) any
|
|
}
|