本文整理汇总了Golang中github.com/jackc/pgx.ConnPool.Prepare方法的典型用法代码示例。如果您正苦于以下问题:Golang ConnPool.Prepare方法的具体用法?Golang ConnPool.Prepare怎么用?Golang ConnPool.Prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jackc/pgx.ConnPool
的用法示例。
在下文中一共展示了ConnPool.Prepare方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpdateFeedWithFetchSuccess
func UpdateFeedWithFetchSuccess(db *pgx.ConnPool, feedID int32, update *ParsedFeed, etag String, fetchTime time.Time) error {
_, err := db.Prepare("updateFeedWithFetchSuccess", updateFeedWithFetchSuccessSQL)
if err != nil {
return err
}
tx, err := db.Begin()
if err != nil {
return err
}
defer tx.Rollback()
_, err = tx.Exec("updateFeedWithFetchSuccess",
update.Name,
fetchTime,
&etag,
feedID)
if err != nil {
return err
}
if len(update.Items) > 0 {
insertSQL, insertArgs := buildNewItemsSQL(feedID, update.Items)
_, err = tx.Exec(insertSQL, insertArgs...)
if err != nil {
return err
}
}
return tx.Commit()
}
示例2: DeleteSubscription
func DeleteSubscription(db *pgx.ConnPool, userID, feedID int32) error {
if _, err := db.Prepare("deleteSubscription", deleteSubscriptionSQL); err != nil {
return err
}
if _, err := db.Prepare("deleteFeedIfOrphaned", deleteFeedIfOrphanedSQL); err != nil {
return err
}
tx, err := db.BeginIso(pgx.Serializable)
if err != nil {
return err
}
defer tx.Rollback()
_, err = tx.Exec("deleteSubscription", userID, feedID)
if err != nil {
return err
}
_, err = tx.Exec("deleteFeedIfOrphaned", feedID)
if err != nil {
return err
}
return tx.Commit()
}
示例3: poolPrepareUseAndDeallocate
func poolPrepareUseAndDeallocate(pool *pgx.ConnPool, actionNum int) error {
psName := fmt.Sprintf("poolPreparedStatement%d", actionNum)
_, err := pool.Prepare(psName, "select $1::text")
if err != nil {
return err
}
var s string
err = pool.QueryRow(psName, "hello").Scan(&s)
if err != nil {
return err
}
if s != "hello" {
return fmt.Errorf("Prepared statement did not return expected value: %v", s)
}
return pool.Deallocate(psName)
}