Skip to content

Commit

Permalink
🐛 fix: upgrade query to QueryExecModeCache
Browse files Browse the repository at this point in the history
This solves problem "statment already exists (SQLSTATE 42P05)" when
using transcation mode in Supabase as mention here
jackc/pgx#1847 (comment)
  • Loading branch information
rodrigomolter committed Aug 11, 2024
1 parent fb7ba6a commit a85e287
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/ama/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/signal"

"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/joho/godotenv"
"github.com/rodrigomolter/ama-backend/internal/api"
Expand All @@ -23,15 +24,21 @@ func main() {
}
ctx := context.Background()

pool, err := pgxpool.New(ctx, fmt.Sprintf(
config, err := pgxpool.ParseConfig(fmt.Sprintf(
"user=%s password=%s host=%s port=%s dbname=%s",
os.Getenv("AMA_DATABASE_USER"),
os.Getenv("AMA_DATABASE_PASSWORD"),
os.Getenv("AMA_DATABASE_HOST"),
os.Getenv("AMA_DATABASE_PORT"),
os.Getenv("AMA_DATABASE_NAME"),
))
if err != nil {
panic(err)
}
// Solves SQLSTATE 42P05 problem when using supabase in transaction mode as mention here https://github.com/jackc/pgx/issues/1847
config.ConnConfig.DefaultQueryExecMode = pgx.QueryExecModeCacheDescribe

pool, err := pgxpool.NewWithConfig(ctx, config)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit a85e287

Please sign in to comment.