本文整理汇总了Golang中github.com/ziutek/mymysql/mysql.Transaction类的典型用法代码示例。如果您正苦于以下问题:Golang Transaction类的具体用法?Golang Transaction怎么用?Golang Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Transaction类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: AddFeed
func AddFeed(transaction mysql.Transaction, uri string) (uint64, error) {
doc := xmlx.New()
if err := doc.LoadUriClient(uri, http.DefaultClient, CharsetReader); err != nil {
return 0, errors.New("Unable to load URI: " + uri)
}
getTitle := func() string {
title := doc.Root.S("*", "title")
if title == "" {
title = doc.SelectNode("*", "channel").S("*", "title")
}
return title
}
getDescription := func() string {
description := doc.Root.S("*", "subtitle")
if description == "" {
description = doc.SelectNode("*", "channel").S("*", "description")
}
return description
}
getLink := func() string {
link := ""
for _, node := range doc.SelectNodes("*", "link") {
if node.As("", "rel") == "alternate" {
link = node.As("", "href")
}
}
if link == "" {
link = doc.SelectNode("*", "channel").S("*", "link")
}
return link
}
_, res, err := transaction.Query("INSERT INTO `feed`(`title`,`description`,`link`,`last_update`,`feedURL`) VALUES ('%s','%s','%s',0,'%s')",
getTitle(),
getDescription(),
getLink(),
uri)
if err != nil {
return 0, err
}
feedId := res.InsertId()
if err := UpdateFeedDocument(transaction, feedId, doc); err != nil {
return 0, err
}
return feedId, nil
}
开发者ID:Nican,项目名称:RabbitReader,代码行数:59,代码来源:updater.go
示例2: Begin
// Begin begins a transaction and calls f to complete it .
// If f returns an error and IsNetErr(error) == true it reconnects and calls
// f up to MaxRetries times. If error is of type *mysql.Error it tries rollback
// the transaction.
func (c *Conn) Begin(f func(mysql.Transaction, ...interface{}) error, args ...interface{}) error {
err := c.connectIfNotConnected()
if err != nil {
return err
}
nn := 0
for {
var tr mysql.Transaction
if tr, err = c.Raw.Begin(); err == nil {
if err = f(tr, args...); err == nil {
return nil
}
}
if c.reconnectIfNetErr(&nn, &err); err != nil {
if _, ok := err.(*mysql.Error); ok && tr.IsValid() {
tr.Rollback()
}
return err
}
}
panic(nil)
}
开发者ID:chogaths,项目名称:robin,代码行数:26,代码来源:autorecon.go
示例3: updatePriorities
func updatePriorities(transaction mysql.Transaction, userId int, newPriorities map[string]GroupInfo) error {
for feedIdStr, priority := range newPriorities {
feedId, err := strconv.ParseInt(feedIdStr, 10, 64)
if err != nil {
return err
}
_, _, err = transaction.Query("UPDATE `user_feed` SET `priority`=%d, `group`='%s' WHERE feed_id=%d AND user_id=%d",
priority.Priority,
gConn.Escape(priority.Group),
feedId,
userId)
if err != nil {
return err
}
}
return nil
}
开发者ID:Nican,项目名称:RabbitReader,代码行数:22,代码来源:web.go
示例4: UpdateFeedDocument
func UpdateFeedDocument(transaction mysql.Transaction, feedId uint64, doc *xmlx.Document) (retErr error) {
defer func() {
if e := recover(); e != nil {
retErr = e.(error)
}
}()
const ns = "*"
findFeedEntry := func(title string, content string, date string, guid string) bool {
search := ""
if len(guid) > 0 {
search = fmt.Sprintf("`guid`='%s'", gConn.Escape(guid))
} else {
where := make([]string, 0)
if len(date) > 0 {
where = append(where, fmt.Sprintf("`published`='%s'", gConn.Escape(date)))
}
if len(content) > 0 {
where = append(where, fmt.Sprintf("`content`='%s'", gConn.Escape(content)))
}
if len(title) > 0 {
where = append(where, fmt.Sprintf("`title`='%s'", gConn.Escape(title)))
}
if len(where) == 0 {
panic(fmt.Sprintf("Can not search item! %s", title))
}
search = strings.Join(where, " OR ")
}
rows, _, err := transaction.Query("SELECT `id` FROM `feed_entry` WHERE `feed_id`=%d AND (%s)",
feedId,
search)
if err != nil {
panic(err)
}
if len(rows) > 1 {
ids := make([]string, len(rows))
for i, row := range rows {
ids[i] = row.Str(0)
}
err := fmt.Sprintf("Found more than one answer! (%s)", strings.Join(ids, ","))
panic(errors.New(err))
}
return len(rows) == 1
}
findItems(doc.Root, func(node *xmlx.Node) {
content := getContent(node)
link := getLink(node)
author := getAuthor(node)
guid := getGUID(node)
title := node.S(ns, "title")
published := node.S(ns, "pubDate")
if len(published) == 0 {
published = node.S(ns, "published")
}
parsedTime, err := parseTime(published)
if err != nil {
fmt.Printf("Warning: Failed to parse (%s)\n", published)
}
if parsedTime.After(time.Now()) {
parsedTime = time.Now()
}
//Thanks VGCats! You have no content! http://www.vgcats.com/vgcats.rdf.xml
//if content == "" {
// panic(errors.New("Could not find content"))
//}
if findFeedEntry(title, content, published, guid) {
return
}
_, _, err = transaction.Query("INSERT INTO `feed_entry`(`feed_id`,`title`,`content`,`published`,`updated`,`author`,`link`,`guid`) VALUES (%d,'%s','%s','%s',%d,'%s','%s','%s')",
feedId,
gConn.Escape(title),
gConn.Escape(content),
gConn.Escape(published),
parsedTime.Unix(),
gConn.Escape(author),
gConn.Escape(link),
gConn.Escape(guid))
if err != nil {
panic(err)
//.........这里部分代码省略.........
开发者ID:Nican,项目名称:RabbitReader,代码行数:101,代码来源:updater.go
注:本文中的github.com/ziutek/mymysql/mysql.Transaction类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论