Ejemplo n.º 1
0
func updateImportInfo(q *qbs.Qbs, path string, pid int, add bool) {
	// Save package information.
	info := new(PkgInfo)
	err := q.WhereEqual("path", path).Find(info)
	if err == nil {
		// Check if pid exists in this project.
		i := strings.Index(info.ImportPid, "$"+strconv.Itoa(pid)+"|")
		switch {
		case i == -1 && add: // Add operation and does not contain.
			info.ImportPid += "$" + strconv.Itoa(pid) + "|"
			info.ImportedNum++
			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.updateImportInfo(): add:", path, err)
			}
		case i > -1 && !add: // Delete operation and contains.
			info.ImportPid = strings.Replace(info.ImportPid, "$"+strconv.Itoa(pid)+"|", "", 1)
			info.ImportedNum--
			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.updateImportInfo(): delete:", path, err)
			}
		}
	}

	// Error means this project does not exist, simply skip.
}
Ejemplo n.º 2
0
//分页查询
func GetEpisodes(q *qbs.Qbs, page int, column string, value interface{}, order string, url string) ([]*Episode, *Pagination) {
	page -= 1
	if page < 0 {
		page = 0
	}

	var episode []*Episode
	var rows int64
	if column == "" {
		fmt.Println(ItemsPerPage)
		fmt.Println(page)
		rows = q.Count("episode")
		err := q.OrderByDesc(order).
			Limit(ItemsPerPage).Offset(page * ItemsPerPage).FindAll(&episode)
		if err != nil {
			fmt.Println(err)
		}
	} else {
		rows = q.WhereEqual(column, value).Count("episode")
		err := q.WhereEqual(column, value).OrderByDesc(order).
			Limit(ItemsPerPage).Offset(page * ItemsPerPage).FindAll(&episode)
		if err != nil {
			fmt.Println(err)
		}
	}
	fmt.Println(episode)
	url = url[:strings.Index(url, "=")+1]
	pagination := NewPagination(page, int(rows), url)

	return episode, pagination
}
Ejemplo n.º 3
0
func UpdateMultipleUsers(q *qbs.Qbs) (affected int64, err error) {
	type User struct {
		Name string
	}
	user := new(User)
	user.Name = "Blue"
	return q.WhereEqual("name", "Green").Update(user)
}
Ejemplo n.º 4
0
func getPkgInfoWithQ(path, tag string, q *qbs.Qbs) (*hv.PkgInfo, error) {
	// Check path length to reduce connect times.
	if len(path) == 0 {
		return nil, errors.New("models.getPkgInfoWithQ -> Empty path as not found.")
	}

	pinfo := new(hv.PkgInfo)
	q.WhereEqual("import_path", path).Find(pinfo)

	proPath := utils.GetProjectPath(path)
	if utils.IsGoRepoPath(path) {
		proPath = "code.google.com/p/go"
	}
	beego.Trace("models.getPkgInfoWithQ -> proPath:", proPath)
	ptag := new(PkgTag)
	cond := qbs.NewCondition("path = ?", proPath).And("tag = ?", tag)
	err := q.Condition(cond).Find(ptag)
	if err != nil {
		pinfo.Ptag = "ptag"
		return pinfo, errors.New(
			fmt.Sprintf("models.getPkgInfoWithQ( %s:%s ) -> 'PkgTag': %s", path, tag, err))
	}
	pinfo.Vcs = ptag.Vcs
	pinfo.Tags = ptag.Tags

	// Only 'PkgInfo' cannot prove that package exists,
	// we have to check 'PkgDecl' as well in case it was deleted by mistake.

	pdecl := new(PkgDecl)
	cond = qbs.NewCondition("pid = ?", pinfo.Id).And("tag = ?", tag)
	err = q.Condition(cond).Find(pdecl)
	if err != nil {
		// Basically, error means not found, so we set 'pinfo.PkgVer' to 0
		// because server uses it to decide whether force update.
		pinfo.PkgVer = 0
		pinfo.Ptag = "ptag"
		return pinfo, errors.New(
			fmt.Sprintf("models.getPkgInfoWithQ( %s:%s ) -> 'PkgDecl': %s", path, tag, err))
	}

	docPath := path + utils.TagSuffix("-", tag)
	if !com.IsExist("." + utils.DocsJsPath + docPath + ".js") {
		pinfo.PkgVer = 0
		pinfo.Ptag = "ptag"
		return pinfo, errors.New(
			fmt.Sprintf("models.getPkgInfoWithQ( %s:%s ) -> JS: File not found", path, tag))
	}

	return pinfo, nil
}
Ejemplo n.º 5
0
func getGroupPkgInfoWithQ(q *qbs.Qbs, paths []string) []*hv.PkgInfo {
	pinfos := make([]*hv.PkgInfo, 0, len(paths))
	for _, v := range paths {
		if len(v) > 0 {
			pinfo := new(hv.PkgInfo)
			err := q.WhereEqual("import_path", v).Find(pinfo)
			if err == nil {
				pinfos = append(pinfos, pinfo)
			} else {
				pinfos = append(pinfos, &hv.PkgInfo{ImportPath: v})
			}
		}
	}
	return pinfos
}
Ejemplo n.º 6
0
func getGroupPkgInfoByIdWithQ(q *qbs.Qbs, pids []string) []*hv.PkgInfo {
	pinfos := make([]*hv.PkgInfo, 0, len(pids))
	for _, v := range pids {
		pid, _ := strconv.ParseInt(v, 10, 64)
		if pid > 0 {
			pinfo := new(hv.PkgInfo)
			err := q.WhereEqual("id", pid).Find(pinfo)
			if err == nil {
				pinfos = append(pinfos, pinfo)
			} else {
				beego.Trace("models.GetGroupPkgInfoById ->", err)
			}
		}
	}
	return pinfos
}
Ejemplo n.º 7
0
func calRefRanks(q *qbs.Qbs, refPids []string) int64 {
	refRank := 0
	for _, spid := range refPids {
		pid, _ := strconv.Atoi(spid)
		if pid == 0 {
			continue
		}
		info := new(hv.PkgInfo)
		err := q.WhereEqual("id", pid).Find(info)
		if err == nil {
			refRank += int(info.Rank) * 10 / 100
		} else {
			beego.Trace("models.calRefRanks ->", err)
		}
	}
	return int64(refRank)
}
Ejemplo n.º 8
0
func FindUserByName(q *qbs.Qbs, n string) (*User, error) {
	user := new(User)
	err := q.WhereEqual("name", n).Find(user)
	return user, err
}
Ejemplo n.º 9
0
/*
* 通过用户编号获得人员信息
* @param  userId 用户编号
* @return person
 */
func (p *Person) findPersonByUserId(userId string, q *qbs.Qbs) *Person {
	person := new(Person)
	q.WhereEqual("user_id", userId).Find(person)
	return person
}
Ejemplo n.º 10
0
//查询验证码是否存在
func FindUserByCode(q *qbs.Qbs, code string) *models.User {
	user := new(models.User)
	q.WhereEqual("validate_code", code).Find(user)
	return user
}
Ejemplo n.º 11
0
func FindUserById(q *qbs.Qbs, id int64) *models.User {
	user := new(models.User)
	q.WhereEqual("id", id).Find(user)
	return user
}
Ejemplo n.º 12
0
func (u *User) HasEmail(q *qbs.Qbs) bool {
	user := new(User)
	q.WhereEqual("email", u.Email).Find(user)

	return user.Id > 0
}
Ejemplo n.º 13
0
func updateImportInfo(q *qbs.Qbs, path string, pid, rank int, add bool) {
	spid := strconv.Itoa(pid)

	// Save package information.
	info := new(hv.PkgInfo)
	err := q.WhereEqual("import_path", path).Find(info)
	if err == nil {
		// Check if pid exists in this project.
		refPids := strings.Split(info.RefPids, "|")
		i := getRefIndex(refPids, spid)

		if add {
			// Add operation.
			if i == -1 {
				refPids = append(refPids, spid)
				i = len(refPids) - 1
			}

			info.RefPids = strings.Join(refPids, "|")
			info.RefNum = len(refPids)
			if info.RefNum > 0 && strings.HasPrefix(info.RefPids, "|") {
				info.RefPids = info.RefPids[1:]
				info.RefNum--
			}

			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.updateImportInfo -> add:", path, err)
			}

		} else if i > -1 {
			// Delete operation
			refPids = append(refPids[:i], refPids[i+1:]...)

			info.RefPids = strings.Join(refPids, "|")
			info.RefNum = len(refPids)
			if info.RefNum > 0 && strings.HasPrefix(info.RefPids, "|") {
				info.RefPids = info.RefPids[1:]
				info.RefNum--
			}

			_, err = q.Save(info)
			if err != nil {
				beego.Error("models.updateImportInfo -> delete:", path, err)
			}
		}
		return
	}

	if add {
		// Record imports.
		pimp := new(PkgImport)
		q.WhereEqual("path", path).Find(pimp)
		pimp.Path = path
		pimps := strings.Split(pimp.Imports, "|")
		i := getRefIndex(pimps, spid)
		if i == -1 {
			pimps = append(pimps, spid)
			pimp.Imports = strings.Join(pimps, "|")
			_, err = q.Save(pimp)
			if err != nil {
				beego.Error("models.updateImportInfo -> record import:", path, err)
			}
		}
	}
}
Ejemplo n.º 14
0
Archivo: t2.go Proyecto: rose312/mzr
func FindNaById(q *qbs.Qbs, id int64) (*Topic, error) {
	na := new(Topic)
	//na.Id = id
	err := q.WhereEqual("id", id).Find(na)
	return na, err
}