Replies: 3 comments
-
It's hard to say what's going on. None of your code snippets have any pgx in them. My guess is your wrapper is doing something funny. See if you can reproduce the issue with calling pgx directly. Also, you might find it useful to step through your code with the debugger. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply @jackc Here's how my connection setup looks... The only thing I am doing out of the ordinary (that I know of) is registering the decimal type, but I also removed that and still ran into the same issue: // DB holds the database
type DB struct{ *sqlx.DB }
// database instance
var defaultDB = &DB{}
func PgxCreateDB(uri string) (*sqlx.DB, error) {
connConfig, _ := pgx.ParseConfig(uri)
afterConnect := stdlib.OptionAfterConnect(func(ctx context.Context, conn *pgx.Conn) error {
// registers decimal type support with driver
pgxdecimal.Register(conn.TypeMap())
return nil
})
logger := logger2.GetLogger()
connConfig.Tracer = pgxslog.NewTracer(logger.Logger)
pgxdb := stdlib.OpenDB(*connConfig, afterConnect)
return sqlx.NewDb(pgxdb, "pgx"), nil
}
// connect sets the db client of database using configuration
func (db *DB) connect(cfg *config.DB) (err error) {
dbURI := fmt.Sprintf("host=%s port=%d sslmode=%s user=%s password=%s dbname=%s",
cfg.Host,
cfg.Port,
cfg.SslMode,
cfg.User,
cfg.Password,
cfg.Name,
)
db.DB, err = PgxCreateDB(dbURI)
if err != nil {
return err
}
// connection pool settings
db.SetMaxOpenConns(cfg.MaxOpenConn)
db.SetMaxIdleConns(cfg.MaxIdleConn)
db.SetConnMaxLifetime(cfg.MaxConnLifetime)
// Try to ping database.
if err := db.Ping(); err != nil {
defer db.Close() // close database connection
return fmt.Errorf("can't send ping to database, %w", err)
}
return nil
}
// GetDB returns db instance
func GetDB() *DB {
return defaultDB
}
// ConnectDB sets the db client of database using default configuration
func ConnectDB() error {
return defaultDB.connect(config.DBCfg())
} I'm just trying to step through the code now to see where args is coming from... |
Beta Was this translation helpful? Give feedback.
-
I was able to sort this out finally using the pg query log, the extra args listed are not in fact being passed to the back-end and the problem was entirely elsewhere. |
Beta Was this translation helpful? Give feedback.
-
Hey, I am stuck with a confusing issue with pgx where it appears to be picking up extra
args
from somewhere. My query is very simple (I trimmed it down to SELECT * to make it shorter as the fields not really relevant):id is a UUID in both the db and the Cart struct/model. The problem is that no matter what value I pass in as the
ID
for this query it will never find a row, even if the row is there - and when I trace the query I see that what it is sending as the args does NOT match what I have passed in as the args above:The UUID at the end of the array there is the correct ID argument, but I'm not able to sort out where all of those other args are coming from.
This only happens on this one query - all other queries properly reflect the args that I have passed in. I have tried changing the arg from a UUID to a string - same thing. I tried removing the argument altogether and hard-coding the UUID into the query - but the same garbage still gets passed in the args. Tried updating all packages, tried registering UUID type, etc. Nothing gets rid of those extraneous args.
Example with UUID hard-coded:
Any insights would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions