本文整理汇总了Golang中github.com/urandom/readeef/content/sql/db.DB.Beginx方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.Beginx方法的具体用法?Golang DB.Beginx怎么用?Golang DB.Beginx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/urandom/readeef/content/sql/db.DB
的用法示例。
在下文中一共展示了DB.Beginx方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: upgrade2to3
func upgrade2to3(db *db.DB) error {
tx, err := db.Beginx()
if err != nil {
return err
}
defer tx.Rollback()
t := time.Now().AddDate(0, -1, 0)
_, err = tx.Exec(upgrade2To3SplitStatesToUnread, t)
if err != nil {
return err
}
_, err = tx.Exec(upgrade2To3SplitStatesToFavorite)
if err != nil {
return err
}
_, err = tx.Exec("DROP TABLE users_articles_states")
if err != nil {
return err
}
return tx.Commit()
}
示例2: upgrade3to4
func upgrade3to4(db *db.DB) error {
table := "users_feeds_tags"
var tabledef string
for _, s := range initSQL {
if strings.Contains(s, table) {
tabledef = s
}
}
if tabledef == "" {
return errors.New("Definition for users_feeds_tags not found")
}
tx, err := db.Beginx()
if err != nil {
return err
}
defer tx.Rollback()
_, err = tx.Exec("ALTER TABLE " + table + " RENAME TO " + table + "2")
if err != nil {
return err
}
_, err = tx.Exec(tabledef)
if err != nil {
return err
}
_, err = tx.Exec(upgrade3To4PopulateTags)
if err != nil {
return err
}
_, err = tx.Exec(upgrade3To4PopulateUsersFeedsTags)
if err != nil {
return err
}
_, err = tx.Exec("DROP TABLE " + table + "2")
if err != nil {
return err
}
return tx.Commit()
}
示例3: upgrade1to2
func upgrade1to2(db *db.DB) error {
tx, err := db.Beginx()
if err != nil {
return err
}
defer tx.Rollback()
_, err = tx.Exec(upgrade1To2MergeReadAndFav)
if err != nil {
return err
}
_, err = tx.Exec("DROP TABLE users_articles_read")
if err != nil {
return err
}
_, err = tx.Exec("DROP TABLE users_articles_fav")
if err != nil {
return err
}
return tx.Commit()
}
示例4: readState
func readState(u content.User, dbo *db.DB, logger webfw.Logger, opts data.ArticleUpdateStateOptions, read bool, join, joinPredicate, deleteJoin, deleteWhere string, insertArgs, deleteArgs []interface{}) {
if u.HasErr() {
return
}
s := dbo.SQL()
var err error
if readStateInsertTemplate == nil {
readStateInsertTemplate, err = template.New("read-state-insert-sql").
Parse(s.User.ReadStateInsertTemplate)
if err != nil {
u.Err(fmt.Errorf("Error generating read-state-insert template: %v", err))
return
}
}
if readStateDeleteTemplate == nil {
readStateDeleteTemplate, err = template.New("read-state-delete-sql").
Parse(s.User.ReadStateDeleteTemplate)
if err != nil {
u.Err(fmt.Errorf("Error generating read-state-delete template: %v", err))
return
}
}
tx, err := dbo.Beginx()
if err != nil {
u.Err(err)
return
}
defer tx.Rollback()
if read {
args := append([]interface{}{u.Data().Login}, deleteArgs...)
buf := util.BufferPool.GetBuffer()
defer util.BufferPool.Put(buf)
data := readStateDeleteData{}
if deleteJoin != "" {
data.Join = deleteJoin
}
if opts.FavoriteOnly {
data.Join += s.User.ReadStateDeleteFavoriteJoin
}
if opts.UntaggedOnly {
data.Join += s.User.ReadStateDeleteUntaggedJoin
}
where := []string{}
if deleteWhere != "" {
where = append(where, deleteWhere)
}
if !opts.BeforeDate.IsZero() {
where = append(where, fmt.Sprintf("(a.date IS NULL OR a.date < $%d)", len(args)+1))
args = append(args, opts.BeforeDate)
}
if !opts.AfterDate.IsZero() {
where = append(where, fmt.Sprintf("a.date > $%d", len(args)+1))
args = append(args, opts.AfterDate)
}
if opts.BeforeId > 0 {
where = append(where, fmt.Sprintf("a.id < $%d", len(args)+1))
args = append(args, opts.BeforeId)
}
if opts.AfterId > 0 {
where = append(where, fmt.Sprintf("a.id > $%d", len(args)+1))
args = append(args, opts.AfterId)
}
if opts.FavoriteOnly {
where = append(where, "af.article_id IS NOT NULL")
}
if opts.UntaggedOnly {
where = append(where, "uft.feed_id IS NULL")
}
if len(where) > 0 {
data.Where = " WHERE " + strings.Join(where, " AND ")
}
if err := readStateDeleteTemplate.Execute(buf, data); err != nil {
u.Err(fmt.Errorf("Error executing read-state-delete template: %v", err))
return
}
sql := buf.String()
logger.Debugf("Read state delete SQL:\n%s\nArgs:%v\n", sql, args)
stmt, err := tx.Preparex(sql)
//.........这里部分代码省略.........