How to make pgx/pgtype with sqlx?

Good day!

Asking for your help. Try to use github.com/jackc/pgx/pgtype with github.com/jmoiron/sqlx
but when saving get the error `pdateRubrica failed: sql: converting argument $1 type: unsupported type pgtype.Varchar, a struct`. If you replace pgtype on normal then everything works. How can I make it work ?

Here is an example code:
type Rubrica struct {
 ID pgtype.Int2 `db:"id"`
 Name pgtype.Varchar `db:"name"`
 Weight pgtype.Int2 `db:"weight"`
}

func Connect(ctx context.Context) *TOPStore {
 d := &stdlib.DriverConfig{
 ConnConfig: pgx.ConnConfig{
 PreferSimpleProtocol: true,
 RuntimeParams: map[string]string{
 "standard_conforming_strings": "on",
},
},
}
stdlib.RegisterDriverConfig(d)

 db, err := sqlx.Connect("pgx", d.ConnectionString(connString))
 if err != nil {
 log.Fatalf("failed to Open sqlx: %v", err)
}
 return db
}

func (s *Store) UpdateRubrica(rub *store.Rubrica) error {
 sql := `UPDATE rubricator SET name=:name, weight=:weight WHERE id=:id`
 if _, err := s.db.NamedExec(sql, rub); err != nil {
 log.Fatalf("failed UpdateRubrica: %-v\n", err)
}
 return nil
}

func main() {
...
 rubrica := store.GetRubrica(1)
store.UpdateRubrica(rubrica)
}
March 30th 20 at 01:12
1 answer
March 30th 20 at 01:14
if _, err := s.db.NamedExec(sql, rub.Name, rub.Weight, rub.ID); err != nil {
 log.Fatalf("failed UpdateRubrica: %-v\n", err)
 }

Find more questions by tags GoPostgreSQL