Skip to content

Commit

Permalink
updates README
Browse files Browse the repository at this point in the history
  • Loading branch information
gosom committed Mar 25, 2023
1 parent 91d6fcc commit fd28a8b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"context"
"database/sql"

"github.com/gosom/gosql2pc"
twophase "github.com/gosom/go-sql-2pc"
_ "github.com/jackc/pgx/stdlib"
)

Expand Down Expand Up @@ -63,23 +63,23 @@ func main() {
amount := 10

// Create the participants for the 2 phase commit
p1 := gosql2pc.NewParticipant(db1, func(ctx context.Context, tx *sql.Tx) error {
p1 := twophase.NewParticipant(db1, func(ctx context.Context, tx *sql.Tx) error {
_, err := tx.ExecContext(ctx, "INSERT INTO users (id, name) VALUES ($1, $2)", userID, name)
return err
})

p2 := gosql2pc.NewParticipant(orderdb, func(ctx context.Context, tx *sql.Tx) error {
p2 := twophase.NewParticipant(orderdb, func(ctx context.Context, tx *sql.Tx) error {
_, err := tx.ExecContext(ctx, "INSERT INTO orders (id, user_id, amount) VALUES ($1, $2, $3)", orderID, userID, amount)
return err
})

// setup the parameters for the transaction
params := gosql2pc.Params{
params := twophase.Params{
Participants: []gosql2pc.Participant{p1, p2},
}

// run the transaction
if err := gosql2pc.Do(context.Background(), params); err != nil {
if err := twophase.Do(context.Background(), params); err != nil {
panic(err)
}
}
Expand Down

0 comments on commit fd28a8b

Please sign in to comment.