本文整理汇总了Golang中github.com/coocood/qbs.NewCondition函数的典型用法代码示例。如果您正苦于以下问题:Golang NewCondition函数的具体用法?Golang NewCondition怎么用?Golang NewCondition使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewCondition函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: SaveProject
// SaveProject save package information, declaration, documentation to database, and update import information.
func SaveProject(pinfo *PkgInfo, pdecl *PkgDecl, pdoc *PkgDoc, imports []string) error {
// Connect to database.
q := connDb()
defer q.Close()
// Save package information.
info := new(PkgInfo)
err := q.WhereEqual("path", pinfo.Path).Find(info)
if err == nil {
pinfo.Id = info.Id
}
_, err = q.Save(pinfo)
if err != nil {
beego.Error("models.SaveProject -> Information:", err)
}
// Save package declaration
if pdecl != nil {
decl := new(PkgDecl)
cond := qbs.NewCondition("path = ?", pinfo.Path).And("tag = ?", pdecl.Tag)
err = q.Condition(cond).Find(decl)
if err == nil {
pdecl.Id = decl.Id
}
_, err = q.Save(pdecl)
if err != nil {
beego.Error("models.SaveProject -> Declaration:", err)
}
}
// Save package documentation
if pdoc != nil && len(pdoc.Doc) > 0 {
_, err = q.Save(pdoc)
if err != nil {
beego.Error("models.SaveProject -> Documentation:", err)
}
}
// Don't need to check standard library.
if imports != nil && !utils.IsGoRepoPath(pinfo.Path) {
// Update import information.
for _, v := range imports {
if !utils.IsGoRepoPath(v) {
// Only count non-standard library.
updateImportInfo(q, v, int(pinfo.Id), true)
}
}
}
return nil
}
开发者ID:seacoastboy,项目名称:gowalker,代码行数:53,代码来源:projects.go
示例17: GetImports
func GetImports(pid, tag string) []*hv.PkgInfo {
q := connDb()
defer q.Close()
pdecl := new(PkgDecl)
cond := qbs.NewCondition("pid = ?", pid).And("tag = ?", tag)
err := q.Condition(cond).Find(pdecl)
if err != nil {
return nil
}
return getGroupPkgInfoWithQ(q, strings.Split(pdecl.Imports, "|"))
}
开发者ID:CharlesSong,项目名称:gowalker,代码行数:13,代码来源:packages.go
示例18: SearchDoc
// SearchDoc returns packages information that contain keyword
func SearchDoc(key string) ([]*PkgInfo, error) {
// Connect to database.
q, err := connDb()
if err != nil {
beego.Error("models.SearchDoc():", err)
}
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:sywxf,项目名称:gowalker,代码行数:14,代码来源:models.go
示例19: GetGoRepo
// GetGoRepo returns packages in go standard library.
func GetGoRepo() ([]*PkgInfo, error) {
// Connect to database.
q, err := connDb()
if err != nil {
beego.Error("models.GetGoRepo():", err)
}
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:sywxf,项目名称:gowalker,代码行数:14,代码来源:models.go
示例20: SearchTopic
func SearchTopic(content string, offset int, limit int, path string) (allt []*Topic) {
//排序首先是热值优先,然后是时间优先。
if content != "" {
q, _ := ConnDb()
defer q.Close()
keyword := "%" + content + "%"
condition := qbs.NewCondition("title like ?", keyword).Or("content like ?", keyword)
q.Condition(condition).Offset(offset).Limit(limit).OrderByDesc(path).OrderByDesc("views").OrderByDesc("reply_count").OrderByDesc("created").FindAll(&allt)
//q.Where("title like ?", keyword).Offset(offset).Limit(limit).OrderByDesc(path).OrderByDesc("created").FindAll(&allt)
return allt
}
return nil
}
开发者ID:hahaya,项目名称:toropress,代码行数:13,代码来源:models.go
注:本文中的github.com/coocood/qbs.NewCondition函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论