Documentation ¶
Index ¶
- Variables
- func Scan(rows *sql.Rows, entityType *types.EntityInfo) (interface{}, error)
- func Scans(rows *sql.Rows, entityType *types.EntityInfo) (interface{}, error)
- type AggregateFunction
- type Condition
- type FieldName
- type Link
- type OrderBy
- type SQLScheme
- func (e *SQLScheme) Aggregate(list []types.IEntity, outType reflect.Type) (bool, reflect.Value)
- func (e *SQLScheme) CheckFieldName(entityAllField []types.StructField) error
- func (e *SQLScheme) CloneAt(params []interface{}) *SQLScheme
- func (e *SQLScheme) Condition(target types.IEntity) bool
- func (e *SQLScheme) CreateBytes() []byte
- func (e *SQLScheme) GenerateFieldCompareMethod(entity *types.EntityInfo, showLog string)
- func (e *SQLScheme) GenerateInsertSQL(entityInfo *types.EntityInfo, value types.IEntity)
- func (e *SQLScheme) GenerateQueryCountSQL() (sqlText string, argNum int, err error)
- func (e *SQLScheme) GenerateSQL() (argNum int, err error)
- func (e *SQLScheme) GenerateUpdateSQL(value interface{}) (int, error)
- func (e *SQLScheme) Order(fieldName string, desc ...bool) *SQLScheme
- func (e *SQLScheme) ParseParams(params []interface{})
- func (e *SQLScheme) ToOrderBy(list []types.IEntity)
- func (e *SQLScheme) Where(fieldName string, value interface{}, condition Condition, link ...Link) *SQLScheme
- type ShiftParams
- type Strings
- func (array *Strings) Append(s ...string)
- func (array Strings) Array() []string
- func (array Strings) Get(index int) string
- func (array Strings) IndexOfContains(s string) int
- func (array Strings) IndexOfEqual(s string) int
- func (array Strings) IndexOfEqualFold(s string) int
- func (array Strings) Len() int
- type WhereCondition
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)) }
参数个数不匹配
Functions ¶
Types ¶
type AggregateFunction ¶
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 IndexOfCondition ¶
type Link ¶
type Link string
* "<", ">", "=", "<>", "<=", ">=",
const LinkAnd Link = "And"
const LinkOr Link = "Or"
type OrderBy ¶
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 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) CheckFieldName ¶
func (e *SQLScheme) CheckFieldName(entityAllField []types.StructField) error
func (*SQLScheme) CreateBytes ¶
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 (*SQLScheme) GenerateSQL ¶
func (*SQLScheme) GenerateUpdateSQL ¶
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) ParseParams ¶
func (e *SQLScheme) ParseParams(params []interface{})
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 (Strings) IndexOfContains ¶
func (Strings) IndexOfEqualFold ¶
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)
Click to show internal directories.
Click to hide internal directories.