本文整理汇总了Golang中github.com/urandom/readeef/content/sql/db.DB.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.Get方法的具体用法?Golang DB.Get怎么用?Golang DB.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/urandom/readeef/content/sql/db.DB
的用法示例。
在下文中一共展示了DB.Get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: articleCount
func articleCount(u content.User, dbo *db.DB, logger webfw.Logger, opts data.ArticleCountOptions, join, where string, args []interface{}) (count int64) {
if u.HasErr() {
return
}
s := dbo.SQL()
var err error
if articleCountTemplate == nil {
articleCountTemplate, err = template.New("article-count-sql").
Parse(s.User.ArticleCountTemplate)
if err != nil {
u.Err(fmt.Errorf("Error generating article-count template: %v", err))
return
}
}
renderData := articleCountData{}
containsUserFeeds := !opts.UnreadOnly && !opts.FavoriteOnly
if containsUserFeeds {
renderData.Join += s.User.ArticleCountUserFeedsJoin
} else {
if opts.UnreadOnly {
renderData.Join += s.User.ArticleCountUnreadJoin
}
if opts.FavoriteOnly {
renderData.Join += s.User.ArticleCountFavoriteJoin
}
}
if opts.UntaggedOnly {
renderData.Join += s.User.ArticleCountUntaggedJoin
}
if join != "" {
renderData.Join += " " + join
}
args = append([]interface{}{u.Data().Login}, args...)
whereSlice := []string{}
if opts.UnreadOnly {
whereSlice = append(whereSlice, "au.article_id IS NOT NULL AND au.user_login = $1")
}
if opts.FavoriteOnly {
whereSlice = append(whereSlice, "af.article_id IS NOT NULL AND af.user_login = $1")
}
if opts.UntaggedOnly {
whereSlice = append(whereSlice, "uft.feed_id IS NULL")
}
if where != "" {
whereSlice = append(whereSlice, where)
}
if opts.BeforeId > 0 {
whereSlice = append(whereSlice, fmt.Sprintf("a.id < $%d", len(args)+1))
args = append(args, opts.BeforeId)
}
if opts.AfterId > 0 {
whereSlice = append(whereSlice, fmt.Sprintf("a.id > $%d", len(args)+1))
args = append(args, opts.AfterId)
}
if !opts.BeforeDate.IsZero() {
whereSlice = append(whereSlice, fmt.Sprintf("(a.date IS NULL OR a.date < $%d)", len(args)+1))
args = append(args, opts.BeforeDate)
}
if !opts.AfterDate.IsZero() {
whereSlice = append(whereSlice, fmt.Sprintf("a.date > $%d", len(args)+1))
args = append(args, opts.AfterDate)
}
if len(whereSlice) > 0 {
renderData.Where = "WHERE " + strings.Join(whereSlice, " AND ")
}
buf := util.BufferPool.GetBuffer()
defer util.BufferPool.Put(buf)
if err := articleCountTemplate.Execute(buf, renderData); err != nil {
u.Err(fmt.Errorf("Error executing article-count template: %v", err))
return
}
sql := buf.String()
logger.Debugf("Article count SQL:\n%s\nArgs:%v\n", sql, args)
if err := dbo.Get(&count, sql, args...); err != nil {
u.Err(err)
return
}
return
}