當前位置: 首頁>>代碼示例>>Golang>>正文


Golang qbs.NewCondition函數代碼示例

本文整理匯總了Golang中github.com/coocood/qbs.NewCondition函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewCondition函數的具體用法?Golang NewCondition怎麽用?Golang NewCondition使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewCondition函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetAllTopicByCidNid

func GetAllTopicByCidNid(cid int64, nid int64, offset int, limit int, ctype int64, path string) (allt []*Topic) {

	q, _ := ConnDb()
	defer q.Close()

	switch {
	case path == "asc":
		if ctype != 0 {
			condition := qbs.NewCondition("cid=?", cid).And("nid=?", nid).And("ctype=?", ctype)
			q.Condition(condition).Offset(offset).Limit(limit).FindAll(&allt)

		} else {

			condition := qbs.NewCondition("cid=?", cid).And("nid=?", nid)
			q.Condition(condition).Offset(offset).Limit(limit).FindAll(&allt)

		}
	default:
		if ctype != 0 {
			condition := qbs.NewCondition("cid=?", cid).And("nid=?", nid).And("ctype=?", ctype)
			q.Condition(condition).Offset(offset).Limit(limit).OrderByDesc(path).OrderByDesc("views").OrderByDesc("reply_count").OrderByDesc("created").FindAll(&allt)

		} else {

			condition := qbs.NewCondition("cid=?", cid).And("nid=?", nid)
			q.Condition(condition).Offset(offset).Limit(limit).OrderByDesc(path).OrderByDesc("views").OrderByDesc("reply_count").OrderByDesc("created").FindAll(&allt)

		}

	}
	return allt
}
開發者ID:hahaya,項目名稱:toropress,代碼行數:32,代碼來源:models.go

示例2: FindUserByCondition

func FindUserByCondition(q *qbs.Qbs) (*User, error) {
	user := new(User)
	condition1 := qbs.NewCondition("id > ?", 100).Or("id < ?", 50).OrEqual("id", 75)
	condition2 := qbs.NewCondition("name != ?", "Red").And("name != ?", "Black")
	condition1.AndCondition(condition2)
	err := q.Condition(condition1).Find(user)
	return user, err
}
開發者ID:nonempty,項目名稱:qbs,代碼行數:8,代碼來源:example.go

示例3: getPkgInfoWithQ

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
}
開發者ID:CharlesSong,項目名稱:gowalker,代碼行數:50,代碼來源:packages.go

示例4: SavePkgDoc

// SavePkgDoc saves readered readme.md file data.
func SavePkgDoc(path string, readmes map[string][]byte) {
	q := connDb()
	defer q.Close()

	for lang, data := range readmes {
		if len(data) == 0 {
			continue
		}

		if data[0] == '\n' {
			data = data[1:]
		}

		pdoc := new(PkgDoc)
		cond := qbs.NewCondition("path = ?", path).And("lang = ?", lang).And("type = ?", "rm")
		q.Condition(cond).Find(pdoc)
		pdoc.Path = path
		pdoc.Lang = lang
		pdoc.Type = "rm"
		pdoc.Doc = base32.StdEncoding.EncodeToString(handleIllegalChars(data))
		_, err := q.Save(pdoc)
		if err != nil {
			beego.Error("models.SavePkgDoc -> readme:", err)
		}
	}
}
開發者ID:CharlesSong,項目名稱:gowalker,代碼行數:27,代碼來源:models.go

示例5: GetPkgInfo

// GetPkgInfo returns package information.
func GetPkgInfo(path, tag string) (*PkgInfo, error) {
	// Check path length to reduce connect times.
	if len(path) == 0 {
		return nil, errors.New("models.GetPkgInfo -> Empty path as not found.")
	}

	// Connect to database.
	q := connDb()
	defer q.Close()

	pinfo := new(PkgInfo)
	err := q.WhereEqual("path", path).Find(pinfo)
	if err != nil {
		return pinfo, errors.New("models.GetPkgInfo -> " + err.Error())
	}

	pdecl := new(PkgDecl)
	cond := qbs.NewCondition("pid = ?", pinfo.Id).And("tag = ?", tag)
	err = q.Condition(cond).Find(pdecl)
	if err != nil {
		pinfo.Etag = ""
		err = errors.New("models.GetPkgInfo -> " + err.Error())
	}
	return pinfo, err
}
開發者ID:JoeyFan,項目名稱:gowalker,代碼行數:26,代碼來源:packages.go

示例6: GetAllNodeByCid

func GetAllNodeByCid(cid int64, offset int, limit int, ctype int64, path string) (alln []*Node) {
	//排序首先是熱值優先,然後是時間優先。
	q, _ := ConnDb()
	defer q.Close()
	switch {
	case path == "asc":
		if ctype != 0 {
			condition := qbs.NewCondition("pid=?", cid).And("ctype=?", ctype)
			q.Condition(condition).Offset(offset).Limit(limit).FindAll(&alln)
		} else {
			if cid == 0 {
				q.Offset(offset).Limit(limit).FindAll(&alln)
			} else {
				q.WhereEqual("pid", cid).Offset(offset).Limit(limit).FindAll(&alln)
			}

		}
	case path == "views" || path == "topic_count":
		if ctype != 0 {
			condition := qbs.NewCondition("pid=?", cid).And("ctype=?", ctype)
			q.Condition(condition).OrderByDesc(path).Offset(offset).Limit(limit).FindAll(&alln)

		} else {
			if cid == 0 {
				q.OrderByDesc(path).Offset(offset).Limit(limit).FindAll(&alln)
			} else {
				q.WhereEqual("pid", cid).OrderByDesc(path).Offset(offset).Limit(limit).FindAll(&alln)
			}

		}
	default:
		if ctype != 0 {

			condition := qbs.NewCondition("pid=?", cid).And("ctype=?", ctype)
			q.Condition(condition).Offset(offset).Limit(limit).OrderByDesc(path).OrderByDesc("views").OrderByDesc("topic_count").OrderByDesc("created").FindAll(&alln)

		} else {
			if cid == 0 {
				q.Offset(offset).Limit(limit).OrderByDesc(path).OrderByDesc("views").OrderByDesc("topic_count").OrderByDesc("created").FindAll(&alln)
			} else {
				q.WhereEqual("pid", cid).Offset(offset).Limit(limit).OrderByDesc(path).OrderByDesc("views").OrderByDesc("topic_count").OrderByDesc("created").FindAll(&alln)
			}
		}

	}
	return alln
}
開發者ID:hahaya,項目名稱:toropress,代碼行數:47,代碼來源:models.go

示例7: SearchRawDoc

// SearchRawDoc returns results for raw page,
// which are package that import path and synopsis contains keyword.
func SearchRawDoc(key string, isMatchSub bool) (pkgInfos []*PkgInfo, err error) {
	// Connect to database.
	q := connDb()
	defer q.Db.Close()

	// Check if need to match sub-packages.
	if isMatchSub {
		condition := qbs.NewCondition("pro_name != ?", "Go")
		condition2 := qbs.NewCondition("path like ?", "%"+key+"%").Or("synopsis like ?", "%"+key+"%")
		err = q.Condition(condition).Condition(condition2).Limit(50).OrderByDesc("views").FindAll(&pkgInfos)
		return pkgInfos, err
	}

	condition := qbs.NewCondition("pro_name like ?", "%"+key+"%").Or("synopsis like ?", "%"+key+"%")
	err = q.Condition(condition).Limit(50).OrderByDesc("views").FindAll(&pkgInfos)
	return pkgInfos, err
}
開發者ID:richardjoo,項目名稱:gowalker,代碼行數:19,代碼來源:models.go

示例8: SearchPkg

// SearchPkg returns packages that import path and synopsis contains keyword.
func SearchPkg(key string) []*hv.PkgInfo {
	q := connDb()
	defer q.Close()

	var pinfos []*hv.PkgInfo
	cond := qbs.NewCondition("import_path like ?", "%"+key+"%").Or("synopsis like ?", "%"+key+"%")
	q.Limit(200).Condition(cond).OrderByDesc("rank").FindAll(&pinfos)
	return pinfos
}
開發者ID:CharlesSong,項目名稱:gowalker,代碼行數:10,代碼來源:packages.go

示例9: QueryDetail

//查詢明細信息
func (this *EpisodeController) QueryDetail(id int64) revel.Result {
	episode := new(models.Episode)
	condition := qbs.NewCondition("id = ?", id)
	this.q.Condition(condition).Find(episode)
	user := FindUserById(this.q, episode.Author)
	episode.User = user
	this.RenderArgs["episode"] = episode
	return this.RenderTemplate("article/detailEpisode.html")
}
開發者ID:river-lee,項目名稱:qishare,代碼行數:10,代碼來源:EpisodeController.go

示例10: GetGoRepo

// GetGoRepo returns packages in go standard library.
func GetGoRepo() ([]*PkgInfo, error) {
	// Connect to database.
	q := connDb()
	defer q.Db.Close()

	var pkgInfos []*PkgInfo
	condition := qbs.NewCondition("pro_name = ?", "Go")
	err := q.Condition(condition).OrderBy("path").FindAll(&pkgInfos)
	return pkgInfos, err
}
開發者ID:richardjoo,項目名稱:gowalker,代碼行數:11,代碼來源:models.go

示例11: LoadPkgDoc

// LoadPkgDoc loads project introduction documentation.
func LoadPkgDoc(path, lang, docType string) (doc string) {
	// Connect to database.
	q := connDb()
	defer q.Close()

	pdoc := new(PkgDoc)
	cond := qbs.NewCondition("path = ?", path).And("lang = ?", lang).And("type = ?", docType)
	err := q.Condition(cond).Find(pdoc)
	if err == nil {
		return pdoc.Doc
	}

	cond = qbs.NewCondition("path = ?", path).And("lang = ?", "en").And("type = ?", docType)
	err = q.Condition(cond).Find(pdoc)
	if err == nil {
		return pdoc.Doc
	}
	return doc
}
開發者ID:seacoastboy,項目名稱:gowalker,代碼行數:20,代碼來源:models.go

示例12: SearchDoc

// SearchDoc returns packages that import path contains keyword.
func SearchDoc(key string) ([]*PkgInfo, error) {
	// Connect to database.
	q := connDb()
	defer q.Db.Close()

	var pkgInfos []*PkgInfo
	condition := qbs.NewCondition("path like ?", "%"+key+"%")
	err := q.Condition(condition).OrderBy("path").FindAll(&pkgInfos)
	return pkgInfos, err
}
開發者ID:richardjoo,項目名稱:gowalker,代碼行數:11,代碼來源:models.go

示例13: HasName

func (c *Category) HasName() bool {
	q, err := qbs.GetQbs()
	if err != nil {
		fmt.Println(err)
	}
	defer q.Close()

	category := new(Category)
	condition := qbs.NewCondition("name = ?", c.Name)
	if c.Id > 0 {
		condition = qbs.NewCondition("name = ?", c.Name).And("id != ?", c.Id)
	}
	err = q.Condition(condition).Find(category)

	if category.Id > 0 {
		return true
	}
	return false

}
開發者ID:jsli,項目名稱:gorevel,代碼行數:20,代碼來源:category.go

示例14: SearchPkg

// SearchPkg returns packages that import path and synopsis contains keyword.
func SearchPkg(key string) []*PkgInfo {
	q := connDb()
	defer q.Close()

	var pinfos []*PkgInfo
	cond := qbs.NewCondition("path like ?", "%"+key+"%").Or("synopsis like ?", "%"+key+"%")
	q.OmitFields("ProName", "IsCmd", "Tags", "Views", "ViewedTime", "Created",
		"Etag", "Labels", "ImportedNum", "ImportPid", "Note").
		Limit(200).Condition(cond).OrderByDesc("rank").FindAll(&pinfos)
	return pinfos
}
開發者ID:JoeyFan,項目名稱:gowalker,代碼行數:12,代碼來源:packages.go

示例15: SavePkgDoc

// SavePkgDoc saves readered readme.md file data.
func SavePkgDoc(path, lang string, docBys []byte) {
	// Connect to database.
	q := connDb()
	defer q.Close()

	// Reader readme.
	doc := string(docBys)
	if len(doc) == 0 {
		return
	}

	if doc[0] == '\n' {
		doc = doc[1:]
	}
	// Remove title and `==========`.
	doc = doc[strings.Index(doc, "\n")+1:]
	if len(doc) == 0 {
		return
	}

	if doc[0] == '=' {
		doc = doc[strings.Index(doc, "\n")+1:]
	}
	// Find all picture path of build system. HAVE BUG!!!
	for _, m := range buildPicPattern.FindAllString(doc, -1) {
		start := strings.Index(m, "http")
		end := strings.Index(m, ")")
		if (start > -1) && (end > -1) && (start < end) {
			picPath := m[start:end]
			doc = strings.Replace(doc, m, "![]("+picPath+")", 1)
		}
	}
	doc = string(blackfriday.MarkdownCommon([]byte(doc)))
	doc = strings.Replace(doc, "h3>", "h5>", -1)
	doc = strings.Replace(doc, "h2>", "h4>", -1)
	doc = strings.Replace(doc, "h1>", "h3>", -1)
	doc = strings.Replace(doc, "<center>", "", -1)
	doc = strings.Replace(doc, "</center>", "", -1)
	doc = "<div style='display:block; padding: 3px; border:1px solid #4F4F4F;'>" + doc + "</div>"

	pdoc := new(PkgDoc)
	cond := qbs.NewCondition("path = ?", path).And("lang = ?", lang).And("type = ?", "rm")
	q.Condition(cond).Find(pdoc)
	pdoc.Path = path
	pdoc.Lang = lang
	pdoc.Type = "rm"
	pdoc.Doc = base32.StdEncoding.EncodeToString([]byte(doc))
	_, err := q.Save(pdoc)
	if err != nil {
		beego.Error("models.SavePkgDoc -> readme:", err)
	}
}
開發者ID:seacoastboy,項目名稱:gowalker,代碼行數:53,代碼來源:models.go


注:本文中的github.com/coocood/qbs.NewCondition函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。