Пример #1
0
// Count executes xorm.Sessions.Count() in slave db
func (xfn XormFunction) Count(obj interface{}, fn func(Session) (int64, error)) (int64, error) {
	db := xfn.orm.Slave(obj)
	if db == nil {
		return 0, errors.NewErrNilDB(NormalizeValue(obj))
	}
	return fn(db.NewSession())
}
Пример #2
0
// Find executes xorm.Sessions.Find() in slave db
func (xfn XormFunction) Find(obj interface{}, fn func(Session) error) error {
	db := xfn.orm.Slave(obj)
	if db == nil {
		return errors.NewErrNilDB(NormalizeValue(obj))
	}
	return fn(db.NewSession())
}
Пример #3
0
// NewMasterSession returns new master session for the db of given object
func (xse *XormSessionManager) NewMasterSession(obj interface{}) (Session, error) {
	db := xse.orm.Master(obj)
	if db == nil {
		return nil, errors.NewErrNilDB(NormalizeValue(obj))
	}

	return db.NewSession(), nil
}
Пример #4
0
// session returns the session for the db of given object
// if old session exists for the object, return it,
// if no session exists for the object, create new one and return it
func (xse *XormSession) session(db Engine, obj interface{}) (Session, error) {
	if db == nil {
		return nil, errors.NewErrNilDB(NormalizeValue(obj))
	}
	// use old session
	s := xse.getSession(db)
	if s != nil {
		return s, nil
	}

	// create new session
	s = db.NewSession()
	xse.addSession(db, s)
	return s, nil
}
Пример #5
0
// session returns the session for the db of given object
// if old session exists for the object, return it,
// if no session exists for the object, create new one and return it
func (xse *XormSessionManager) session(id Identifier, obj interface{}, db Engine) (Session, error) {
	if db == nil {
		return nil, errors.NewErrNilDB(NormalizeValue(obj))
	}
	// use old session

	s := xse.getSessionFromList(id, db)
	if s != nil {
		return s, nil
	}

	// create new session
	s = db.NewSession()
	xse.addSessionIntoList(id, db, s)
	return s, nil
}
Пример #6
0
// transaction returns the session with transaction for the db of given object
// if old transaction exists for the object, return it,
// if no transaction exists for the object, create new one and return it
func (xse *XormSessionManager) transaction(id Identifier, obj interface{}, db Engine) (Session, error) {
	if db == nil {
		return nil, errors.NewErrNilDB(NormalizeValue(obj))
	}
	// use old transaction
	s := xse.getTransactionFromList(id, db)
	if s != nil {
		return s, nil
	}

	// create new transaction
	s = db.NewSession()
	err := s.Begin()
	if err != nil {
		return nil, err
	}

	// save created session with transaction
	xse.addTransactionIntoList(id, db, s)
	return s, nil
}
Пример #7
0
// transaction returns the session with transaction for the db of given object
// if old transaction exists for the object, return it,
// if no transaction exists for the object, create new one and return it
func (xtx *XormTransaction) transaction(db Engine, obj interface{}) (Session, error) {
	if db == nil {
		return nil, errors.NewErrNilDB(NormalizeValue(obj))
	}
	// use old transaction
	s := xtx.getTransaction(db)
	if s != nil {
		return s, nil
	}

	// create new transaction
	s = db.NewSession()
	err := s.Begin()
	if err != nil {
		return nil, err
	}

	// save created session with transaction
	xtx.addTransaction(db, s)
	return s, nil
}
Пример #8
0
func newSession(db Engine, obj interface{}) (Session, error) {
	if db == nil {
		return nil, errors.NewErrNilDB(NormalizeValue(obj))
	}
	return db.NewSession(), nil
}