rank_range_data.go 1.7 KB
package models

import (
	"github.com/astaxie/beego/orm"
)

type RankRangeData struct {
	Id          int64 `orm:"column(id);auto"`
	RankRangeId int64 `orm:"column(rank_range_id)"`
	RangeType   int8  `orm:"column(range_type);" description:"类型"`
	RelationId  int64 `orm:"column(relation_id);"`
	RankTypeId  int64 `orm:"column(rank_type_id)"`
}

func (t *RankRangeData) TableName() string {
	return "rank_range_data"
}

func init() {
	orm.RegisterModel(new(RankRangeData))
}

// AddRankRangeData insert a new RankRangeData into database and returns
// last inserted Id on success.
func AddRankRangeDataMulti(m []RankRangeData, om ...orm.Ormer) (successNums int64, err error) {
	var o orm.Ormer
	if len(om) > 0 {
		o = om[0]
	} else {
		o = orm.NewOrm()
	}
	successNums, err = o.InsertMulti(20, m)
	return
}

// GetRankRangeDataById retrieves RankRangeData by Id. Returns error if
// Id doesn't exist
func GetRankRangeDataById(id int64) (v *RankRangeData, err error) {
	o := orm.NewOrm()
	v = &RankRangeData{Id: id}
	if err = o.Read(v); err == nil {
		return v, nil
	}
	return nil, err
}

// DeleteRankRangeData deletes RankRangeData by Id and returns error if
// the record to be deleted doesn't exist
func DeleteRankRangeData(id []int64, om orm.Ormer) (err error) {

	_, err = om.QueryTable(&RankRangeData{}).
		Filter("id__in", id).
		Delete()
	return err
}

func GetRankRangeDataByRangeId(id int64) ([]RankRangeData, error) {
	var (
		data = make([]RankRangeData, 0)
		err  error
	)
	o := orm.NewOrm()
	_, err = o.QueryTable(&RankRangeData{}).
		Filter("rank_range_id", id).
		All(&data)
	if err == orm.ErrNoRows {
		return data, nil
	}
	if err != nil {
		return nil, err
	}
	return data, nil
}