本文整理汇总了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
}
示例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
}
示例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
}
示例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)
}
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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")
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
}