Remove pgproto3/v2 dep by upgrading pgx/v4 to v5
pgx/v4/stdlib was only used in test infrastructure, but its transitive dependency on jackc/pgproto3/v2 exposed the build to GO-2026-4518 (DoS via negative field length panic in DataRow.Decode). Replaces the pgconn.ParseConfig call via GenerateDSN with url.Parse for DSN validation, and SELECT current_database() for retrieving the database name, removing the last non-test dependency on the pgx/v4. Updates TestUInt64Overflow in tests/postgres to match pgx/v5 error format: v5 renamed Int to Int64 across pgtype to match database/sql conventions, so the overflow error now says "int64" instead of "Int8". Bumps minimum Go version to 1.24 (required by pgx/v5).
This commit is contained in:
parent
6c2abe9dd1
commit
ea8a35d497
6 changed files with 46 additions and 36 deletions
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/go-jet/jet/v2/generator/metadata"
|
||||
"github.com/go-jet/jet/v2/generator/template"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/jackc/pgconn"
|
||||
)
|
||||
|
||||
// DBConnection contains postgres connection details
|
||||
|
|
@ -43,21 +42,28 @@ func Generate(destDir string, dbConn DBConnection, genTemplate ...template.Templ
|
|||
|
||||
// GenerateDSN generates jet files using dsn connection string
|
||||
func GenerateDSN(dsn, schema, destDir string, templates ...template.Template) error {
|
||||
cfg, err := pgconn.ParseConfig(dsn)
|
||||
_, err := url.Parse(dsn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse config: %w", err)
|
||||
}
|
||||
if cfg.Database == "" {
|
||||
return fmt.Errorf("database name is required")
|
||||
return fmt.Errorf("failed to parse as DSN: %w", err)
|
||||
}
|
||||
|
||||
db, err := openConnection(dsn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open db connection: %w", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
var dbName string
|
||||
err = db.QueryRow("SELECT current_database()").Scan(&dbName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get current database name: %w", err)
|
||||
}
|
||||
if dbName == "" {
|
||||
return fmt.Errorf("database name is required")
|
||||
}
|
||||
|
||||
fmt.Println("Retrieving schema information...")
|
||||
return GenerateDB(db, schema, filepath.Join(destDir, cfg.Database), templates...)
|
||||
return GenerateDB(db, schema, filepath.Join(destDir, dbName), templates...)
|
||||
}
|
||||
|
||||
// GenerateDB generates jet files using the provided *sql.DB
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue