scheme

package
v0.0.0-...-afb9b83 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsInvalidError = func(logName string, invalid interface{}) error {
	return errors.New(fmt.Sprintf("%v:[%v] Is Invalid", logName, invalid))
}
View Source
var NotFindEntityRepositoryError = func(logName string, entityRepository interface{}) error {
	return errors.New(fmt.Sprintf("%v:找不到Repository实例(%v),确定调用了Bind方法?", logName, entityRepository))
}
View Source
var NotFindFieldError = func(logName string, tableName types.TableName, fieldName string) error {
	return errors.New(fmt.Sprintf("%v:表(%v)字段(%v)不存在", logName, tableName, fieldName))
}
View Source
var NotSupportedTypeError = func(typeName string) error {
	return errors.New(fmt.Sprintf("不支持类型:[%v]", typeName))
}
View Source
var ParamsNumberError = func() error {
	return errors.New(fmt.Sprintf("参数个数不匹配"))
}

参数个数不匹配

Functions

func Scan

func Scan(rows *sql.Rows, entityType *types.EntityInfo) (interface{}, error)

func Scans

func Scans(rows *sql.Rows, entityType *types.EntityInfo) (interface{}, error)

Types

type AggregateFunction

type AggregateFunction struct {
	Columns  []string
	Function string
	AreaName string
}

type Condition

type Condition string
const ConditionBetween Condition = "Between"
const ConditionEq Condition = "Eq"
const ConditionGe Condition = "Ge"
const ConditionGt Condition = "Gt"
const ConditionIn Condition = "In"
const ConditionIsNull Condition = "IsNull"
const ConditionLe Condition = "Le"
const ConditionLike Condition = "Like"
const ConditionLt Condition = "Lt"
const ConditionNe Condition = "Ne"

func FetchOperaSymbol

func FetchOperaSymbol(symbol string) (bool, Condition, string)

提取操作符号到字面字符

func IndexOfCondition

func IndexOfCondition(condition string) (bool, Condition)

func (Condition) String

func (s Condition) String() string

type FieldName

type FieldName struct {
	FieldName string
	Condition Condition
	IsNOT     bool
}
type Link string

* "<", ">", "=", "<>", "<=", ">=",

const LinkAnd Link = "And"
const LinkOr Link = "Or"

func (Link) String

func (s Link) String() string

type OrderBy

type OrderBy struct {
	Column string
	Desc   bool
}

func ParseOrderBy

func ParseOrderBy(order interface{}) []OrderBy

type SQLScheme

type SQLScheme struct {
	ShowLog           string
	Conditions        []WhereCondition
	AggregateFunction []AggregateFunction
	OrderBy           []OrderBy
	GroupBy           string
	IsLimit           bool //是否有分页
	IsMany            bool // 要得到多记录还是单条记录
	TableName         types.TableName
	OperationType     types.OperationType
	SQL               string
	IgnoreCase        bool
	DefaultParams     []interface{}
	// contains filtered or unexported fields
}
func (c *Condition) AddValue(whereValue string) {
	if strings.Contains(whereValue, "?") {
		has, value := c.ShiftParams.Shift()
		if has == false {
			panic(errors.New("参数个数匹配"))
		}

		vt := reflect.TypeOf(value)
		log.Println(vt.Kind())

	}
	c.Values = append(c.Values, whereValue)
}

func Generate

func Generate(entity types.IEntity, entityType *types.EntityInfo) *SQLScheme

func NewSQLScheme

func NewSQLScheme(tableName types.TableName, entityType *types.EntityInfo, operationType types.OperationType, aggregateFunctionList []AggregateFunction, whereConditionList []WhereCondition, orderBy []OrderBy, groupBy string, isMany, isLimit bool, showLog string) *SQLScheme

func (*SQLScheme) Aggregate

func (e *SQLScheme) Aggregate(list []types.IEntity, outType reflect.Type) (bool, reflect.Value)

func (*SQLScheme) CheckFieldName

func (e *SQLScheme) CheckFieldName(entityAllField []types.StructField) error

func (*SQLScheme) CloneAt

func (e *SQLScheme) CloneAt(params []interface{}) *SQLScheme

func (*SQLScheme) Condition

func (e *SQLScheme) Condition(target types.IEntity) bool

func (*SQLScheme) CreateBytes

func (e *SQLScheme) CreateBytes() []byte

func (*SQLScheme) GenerateFieldCompareMethod

func (e *SQLScheme) GenerateFieldCompareMethod(entity *types.EntityInfo, showLog string)
func (e *SQLScheme) Scan(row *sql.Rows, entityType *types.EntityInfo) (interface{}, error) {
	ColumnTypes := entityType.GetFieldNameList()
	values := make([]interface{}, 0, len(ColumnTypes))
	for i := range ColumnTypes {
		//log.Println(ColumnTypes[i].Name())
		//log.Println(ColumnTypes[i].ScanType())
		//log.Println(ColumnTypes[i].DatabaseTypeName())
		//log.Println(ColumnTypes[i].DecimalSize())
		//log.Println(ColumnTypes[i].Length())
		//log.Println(ColumnTypes[i].Nullable())
		fieldValue := reflect.New(ColumnTypes[i].Type)

		values = append(values, fieldValue.Interface())
		//log.Println(ColumnTypes[i].Type.Name(),fieldValue.Kind(),fieldValue.Elem().Interface())
	}
	newEntity := entityType.NewEntityValue()
	err := row.Scan(values...)
	if glog.CheckError(err) {
		return newEntity.Interface(), err
	}

	newEntityElem := newEntity.Elem()
	for i := range ColumnTypes {

		//var setValue  interface{}
		v := newEntityElem.FieldByName(ColumnTypes[i].Column)
		vType := v.Type()

		df, ok := values[i].(driver.Valuer)

		if ok {
			asdf, err := df.Value()
			if glog.Error(err) {
				return newEntity.Interface().(types.IEntity), err
			}
			v.Set(object.Convert(reflect.ValueOf(asdf), vType))
		} else {
			vp := reflect.ValueOf(values[i])
			if vp.Kind() == reflect.Ptr {
				v.Set(object.Convert(vp.Elem(), vType))
			} else {
				v.Set(object.Convert(vp, vType))
			}

		}

		//log.Println(vType.Kind(), reflect.ValueOf(values[i]).Elem().Kind())

	}

	return newEntity.Interface(), err
}

func (*SQLScheme) GenerateInsertSQL

func (e *SQLScheme) GenerateInsertSQL(entityInfo *types.EntityInfo, value types.IEntity)

func (*SQLScheme) GenerateQueryCountSQL

func (e *SQLScheme) GenerateQueryCountSQL() (sqlText string, argNum int, err error)

func (*SQLScheme) GenerateSQL

func (e *SQLScheme) GenerateSQL() (argNum int, err error)

func (*SQLScheme) GenerateUpdateSQL

func (e *SQLScheme) GenerateUpdateSQL(value interface{}) (int, error)
func (e *SQLScheme) GenerateDeleteSQL() (int, error) {
    argsNum, whereSql, err := e.whereSQL()
    if glog.CheckError(err) {
        return 0, err
    }
    //DELETE FROM `operation_dev`.`TestUser` WHERE  `ID`=271;
    sql := fmt.Sprintf("DELETE FROM `%v` WHERE %v", e.TableName, whereSql)
    e.SQL = sql
    return argsNum, nil
}

func (*SQLScheme) Order

func (e *SQLScheme) Order(fieldName string, desc ...bool) *SQLScheme

func (*SQLScheme) ParseParams

func (e *SQLScheme) ParseParams(params []interface{})

func (*SQLScheme) ToOrderBy

func (e *SQLScheme) ToOrderBy(list []types.IEntity)

func (*SQLScheme) Where

func (e *SQLScheme) Where(fieldName string, value interface{}, condition Condition, link ...Link) *SQLScheme

type ShiftParams

type ShiftParams struct {
	// contains filtered or unexported fields
}

func NewShiftParams

func NewShiftParams(arr []interface{}) *ShiftParams

func (*ShiftParams) Shift

func (s *ShiftParams) Shift() (exist bool, v interface{})

type Strings

type Strings []string

func NewStrings

func NewStrings(arr []string, removeEmpty ...bool) Strings

func (*Strings) Append

func (array *Strings) Append(s ...string)

func (Strings) Array

func (array Strings) Array() []string

func (Strings) Get

func (array Strings) Get(index int) string

func (Strings) IndexOfContains

func (array Strings) IndexOfContains(s string) int

func (Strings) IndexOfEqual

func (array Strings) IndexOfEqual(s string) int

-1 没有找到

func (Strings) IndexOfEqualFold

func (array Strings) IndexOfEqualFold(s string) int

func (Strings) Len

func (array Strings) Len() int

type WhereCondition

type WhereCondition struct {
	Column               string
	Condition            Condition
	Values               []types.WhereConditionValue //值或点位符
	Link                 Link
	LikeMods             []types.LikeMod
	IsNOT                bool
	ConditionParamsCount int                   //匹配 ? 点位符的个数
	FieldCompare         compare.IFieldCompare //比较方法
}

func (*WhereCondition) AddValue

func (c *WhereCondition) AddValue(whereValue types.WhereConditionValue)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL