/*
Returns a RoleGroup matching the id inside the given RoleGroup. If no match is found, the RoleGroup is added to the database
*/
Returns a RoleGroup matching the id inside the given RoleGroup. If no match is found, the RoleGroup is added to the database
/ * Returns a RoleGroup matching the id inside the given RoleGroup . If no match is found the RoleGroup is added to the database * /
func RoleGroupQueryOrInsert(rg types.RoleGroup, s types.Server) (newRg types.RoleGroup, err error) {
	row := moeDb.QueryRow(roleGroupQueryById, rg.Id)
	if err = row.Scan(&newRg.Id, &newRg.ServerId, &newRg.Name, &newRg.Type); err != nil {
		if err == sql.ErrNoRows {
			if rg.Type <= 0 {
				rg.Type = types.GroupTypeAny
			}
			var insertId int
			err = moeDb.QueryRow(roleGroupInsert, s.Id, rg.Name, rg.Type).Scan(&insertId)
			if err != nil {
				log.Println("Error inserting role to db")
				return
			}
			newRg.Id = insertId
		} else {
			log.Println("Error scanning in roleGroup", err)
			return types.RoleGroup{}, err
		}
	}
	return
}
func RoleGroupQueryOrInsert ( rg types . RoleGroup , s types . Server ) ( newRg types . RoleGroup , err error ) { row := moeDb . QueryRow ( roleGroupQueryById , rg . Id ) if err = row . Scan ( & newRg . Id , & newRg . ServerId , & newRg . Name , & newRg . Type ) ; err != nil { if err == sql . ErrNoRows { if rg . Type <= 0 { rg . Type = types . GroupTypeAny } var insertId int err = moeDb . QueryRow ( roleGroupInsert , s . Id , rg . Name , rg . Type ) . Scan ( & insertId ) if err != nil { log . Println ( " " ) return } newRg . Id = insertId } else { log . Println ( " " , err ) return types . RoleGroup { } , err } } return }
Returns a RoleGroup matching the id inside the given RoleGroup.
Returns a RoleGroup matching the id inside the given RoleGroup .
// no row, so insert it add in default values // no need to re-query since we inserted a row