Exemple #1
0
func (this *Model) Sess() *xorm.Session { // TransSession or Session
	ss, ok := this.transSession()
	if ok == false {
		var ss *xorm.Session = this.DB.NewSession()
		ss.IsAutoClose = true
		return ss
	}
	return ss
}
Exemple #2
0
func (this *Model) End(result bool, args ...*xorm.Session) (err error) {
	var ss *xorm.Session
	if len(args) > 0 && args[0] != nil {
		ss = args[0]
	} else {
		ss, _ = this.transSession()
	}
	if result {
		err = ss.Commit()
	} else {
		err = ss.Rollback()
	}
	if err != nil {
		this.Context.Object().Echo().Logger().Error(err)
	}
	ss.Close()
	this.Context.Set(`webx:transSession`, nil)
	return
}
Exemple #3
0
func (a *Select) GenSess(args ...interface{}) *xorm.Session {
	var s *xorm.Session = a.Orm.NewSession()
	s.IsAutoClose = true
	switch len(args) {
	case 2:
		alias, _ := args[1].(string)
		if args[0] == nil {
			s = s.Alias(alias)
		} else {
			s = s.Table(args[0]).Alias(alias)
			a.Table = args[0]
		}
		a.Alias = alias
	case 1:
		s = s.Table(args[0])
		a.Table = args[0]
	default:
		if a.Table != nil {
			s = s.Table(a.Table)
		}
		if a.Alias != `` {
			s = s.Alias(a.Alias)
		}
	}
	s = s.Where(a.Condition, a.Params...).GroupBy(a.GroupBy)
	if a.Having != `` {
		s = s.Having(a.Having)
	}
	return s
}