Open bbonagura9 opened 7 months ago
I personally solved it with this:
5d4
< "database/sql"
11,12c10,11
< func bumpCounter(ctx context.Context, db *sql.DB, queries *dbsqlc.Queries, id int32) error {
< tx, err := db.Begin()
---
> func bumpCounter(ctx context.Context, db *pgx.Conn, queries *dbsqlc.Queries, id int32) error {
> tx, err := db.Begin(ctx)
16c15
< defer tx.Rollback()
---
> defer tx.Rollback(ctx)
28c27
< return tx.Commit()
---
> return tx.Commit(ctx)
pgx.Conn
as the db parameter typectx
on Begin
, Rollback
and Commit
Does anyone think this should be fixed on the documentation? I can open a PR if you think so.
Sorry about the confusion. That documentation was written when we only supported github/lib/pq. You'll need to update it to use pgx
if you're using pgx.
@bbonagura9 Instead of updating the example, could you create a second one for pgx? That would be excellent.
Overview
I was trying to implement a simple transaction following the documentation but it's not clear and the code return errors.
Details to reproduce
Files:
schema.sql
query.sql
sqlc.yaml
main.go
Issues encontered
Just like the documentation indicates. But I came to two problems:
./main.go:17:24: cannot use tx (variable of type *sql.Tx) as pgx.Tx value in argument to queries.WithTx: *sql.Tx does not implement pgx.Tx (missing method Begin)
./main.go:41:20: cannot use conn (variable of type *pgx.Conn) as *sql.DB value in argument to bumpCounter
Questions
Aditional info
Thanks!