func (mp *MysqlProvider) AssignList(entity dal.QueryEntity, output interface{}) error { data, err := mp.List(entity) if err != nil { return err } return utils.NewDecoder(&data).Decode(output) }
func (mp *MysqlProvider) Pager(entity dal.QueryEntity) (dal.QueryPagerResult, error) { var qResult dal.QueryPagerResult if entity.ResultType != dal.QPager { entity.ResultType = dal.QPager } sqlText, values := mp.parseQuerySQL(entity) if mp.config.IsPrint { mp.PrintSQL(sqlText[0], values...) mp.PrintSQL(sqlText[1], values...) } var ( errs []error mux = new(sync.RWMutex) wg = new(sync.WaitGroup) ) wg.Add(2) go func(result *dal.QueryPagerResult, errs *[]error) { defer wg.Done() rData := make([]map[string]interface{}, 0) data, err := mp.queryData(sqlText[0], values...) mux.Lock() defer mux.Unlock() if err != nil { *errs = append(*errs, err) return } if len(data) > 0 { err = utils.NewDecoder(data).Decode(&rData) if err != nil { *errs = append(*errs, err) return } } (*result).Rows = rData }(&qResult, &errs) go func(result *dal.QueryPagerResult, errs *[]error) { defer wg.Done() var count int64 row := GDB.QueryRow(sqlText[1], values...) err := row.Scan(&count) mux.Lock() defer mux.Unlock() if err != nil { *errs = append(*errs, err) return } (*result).Total = count }(&qResult, &errs) wg.Wait() if len(errs) > 0 { return qResult, mp.Error(errs[0].Error()) } return qResult, nil }
// NewTranAEntity 创建新增实体 // fieldsValue 数据类型(map[string]interface{} or map[string]string or struct) // 如果fieldsValue为struct类型,只保留非零值字段 func NewTranAEntity(table string, fieldsValue interface{}) TranEntityResult { var result TranEntityResult entity := TranEntity{ Table: table, Operate: TA, } var fields map[string]interface{} err := utils.NewDecoder(fieldsValue).Decode(&fields) if err != nil { result.Error = err } entity.FieldsValue = fields result.Entity = entity return result }