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() }
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() }
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) }