From 4b4596ec30799aac1897cbface6f74c39b3cb63a Mon Sep 17 00:00:00 2001 From: Suman De Date: Thu, 19 Mar 2026 02:34:19 +0530 Subject: [PATCH 1/6] feat: add support for yugabyte smart driver --- internal/codegen/golang/driver.go | 2 + internal/codegen/golang/imports.go | 10 +++ internal/codegen/golang/opts/enum.go | 20 ++++-- internal/codegen/golang/postgresql_type.go | 78 +++++++++++----------- 4 files changed, 64 insertions(+), 46 deletions(-) diff --git a/internal/codegen/golang/driver.go b/internal/codegen/golang/driver.go index 5e3a533dcc..6112ac12e5 100644 --- a/internal/codegen/golang/driver.go +++ b/internal/codegen/golang/driver.go @@ -8,6 +8,8 @@ func parseDriver(sqlPackage string) opts.SQLDriver { return opts.SQLDriverPGXV4 case opts.SQLPackagePGXV5: return opts.SQLDriverPGXV5 + case opts.SQLPackageYugaBytePGXV5: + return opts.SQLDriverYugaBytePGXV5 default: return opts.SQLDriverLibPQ } diff --git a/internal/codegen/golang/imports.go b/internal/codegen/golang/imports.go index ccca4f603c..e606cd6027 100644 --- a/internal/codegen/golang/imports.go +++ b/internal/codegen/golang/imports.go @@ -132,6 +132,10 @@ func (i *importer) dbImports() fileImports { case opts.SQLDriverPGXV5: pkg = append(pkg, ImportSpec{Path: "github.com/jackc/pgx/v5/pgconn"}) pkg = append(pkg, ImportSpec{Path: "github.com/jackc/pgx/v5"}) + + case opts.SQLDriverYugaBytePGXV5: + pkg = append(pkg, ImportSpec{Path: "github.com/yugabyte/pgx/v5/pgconn"}) + pkg = append(pkg, ImportSpec{Path: "github.com/yugabyte/pgx/v5"}) default: std = append(std, ImportSpec{Path: "database/sql"}) if i.Options.EmitPreparedQueries { @@ -176,6 +180,8 @@ func buildImports(options *opts.Options, queries []Query, uses func(string) bool pkg[ImportSpec{Path: "github.com/jackc/pgconn"}] = struct{}{} case opts.SQLDriverPGXV5: pkg[ImportSpec{Path: "github.com/jackc/pgx/v5/pgconn"}] = struct{}{} + case opts.SQLDriverYugaBytePGXV5: + pkg[ImportSpec{Path: "github.com/yugabyte/pgx/v5/pgconn"}] = struct{}{} default: std["database/sql"] = struct{}{} } @@ -191,6 +197,8 @@ func buildImports(options *opts.Options, queries []Query, uses func(string) bool if uses("pgtype.") { if sqlpkg == opts.SQLDriverPGXV5 { pkg[ImportSpec{Path: "github.com/jackc/pgx/v5/pgtype"}] = struct{}{} + } else if sqlpkg == opts.SQLDriverYugaBytePGXV5 { + pkg[ImportSpec{Path: "github.com/yugabyte/pgx/v5/pgtype"}] = struct{}{} } else { pkg[ImportSpec{Path: "github.com/jackc/pgtype"}] = struct{}{} } @@ -489,6 +497,8 @@ func (i *importer) batchImports() fileImports { pkg[ImportSpec{Path: "github.com/jackc/pgx/v4"}] = struct{}{} case opts.SQLDriverPGXV5: pkg[ImportSpec{Path: "github.com/jackc/pgx/v5"}] = struct{}{} + case opts.SQLDriverYugaBytePGXV5: + pkg[ImportSpec{Path: "github.com/yugabyte/pgx/v5"}] = struct{}{} } return sortedImports(std, pkg) diff --git a/internal/codegen/golang/opts/enum.go b/internal/codegen/golang/opts/enum.go index 40457d040a..fc199c0b47 100644 --- a/internal/codegen/golang/opts/enum.go +++ b/internal/codegen/golang/opts/enum.go @@ -5,15 +5,17 @@ import "fmt" type SQLDriver string const ( - SQLPackagePGXV4 string = "pgx/v4" - SQLPackagePGXV5 string = "pgx/v5" - SQLPackageStandard string = "database/sql" + SQLPackagePGXV4 string = "pgx/v4" + SQLPackagePGXV5 string = "pgx/v5" + SQLPackageStandard string = "database/sql" + SQLPackageYugaBytePGXV5 string = "yb/pgx/v5" ) var validPackages = map[string]struct{}{ - string(SQLPackagePGXV4): {}, - string(SQLPackagePGXV5): {}, - string(SQLPackageStandard): {}, + string(SQLPackagePGXV4): {}, + string(SQLPackagePGXV5): {}, + string(SQLPackageYugaBytePGXV5): {}, + string(SQLPackageStandard): {}, } func validatePackage(sqlPackage string) error { @@ -28,6 +30,7 @@ const ( SQLDriverPGXV5 = "github.com/jackc/pgx/v5" SQLDriverLibPQ = "github.com/lib/pq" SQLDriverGoSQLDriverMySQL = "github.com/go-sql-driver/mysql" + SQLDriverYugaBytePGXV5 = "github.com/yugabyte/pgx/v5" ) var validDrivers = map[string]struct{}{ @@ -35,6 +38,7 @@ var validDrivers = map[string]struct{}{ string(SQLDriverPGXV5): {}, string(SQLDriverLibPQ): {}, string(SQLDriverGoSQLDriverMySQL): {}, + string(SQLDriverYugaBytePGXV5): {}, } func validateDriver(sqlDriver string) error { @@ -45,7 +49,7 @@ func validateDriver(sqlDriver string) error { } func (d SQLDriver) IsPGX() bool { - return d == SQLDriverPGXV4 || d == SQLDriverPGXV5 + return d == SQLDriverPGXV4 || d == SQLDriverPGXV5 || d == SQLDriverYugaBytePGXV5 } func (d SQLDriver) IsGoSQLDriverMySQL() bool { @@ -58,6 +62,8 @@ func (d SQLDriver) Package() string { return SQLPackagePGXV4 case SQLDriverPGXV5: return SQLPackagePGXV5 + case SQLDriverYugaBytePGXV5: + return SQLPackageYugaBytePGXV5 default: return SQLPackageStandard } diff --git a/internal/codegen/golang/postgresql_type.go b/internal/codegen/golang/postgresql_type.go index 398d01e2e8..cc830c3752 100644 --- a/internal/codegen/golang/postgresql_type.go +++ b/internal/codegen/golang/postgresql_type.go @@ -48,7 +48,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int32" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Int4" } return "sql.NullInt32" @@ -60,7 +60,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int64" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Int8" } return "sql.NullInt64" @@ -72,7 +72,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int16" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Int2" } return "sql.NullInt16" @@ -84,7 +84,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int32" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Int4" } return "sql.NullInt32" @@ -96,7 +96,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int64" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Int8" } return "sql.NullInt64" @@ -108,7 +108,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int16" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Int2" } return "sql.NullInt16" @@ -120,7 +120,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*float64" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Float8" } return "sql.NullFloat64" @@ -132,7 +132,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*float32" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Float4" } return "sql.NullFloat64" // TODO: Change to sql.NullFloat32 after updating the go.mod file @@ -160,14 +160,14 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*bool" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Bool" } return "sql.NullBool" case "json", "pg_catalog.json": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "[]byte" case opts.SQLDriverPGXV4: return "pgtype.JSON" @@ -183,7 +183,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "jsonb", "pg_catalog.jsonb": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "[]byte" case opts.SQLDriverPGXV4: return "pgtype.JSONB" @@ -201,7 +201,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi return "[]byte" case "date": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Date" } if notNull { @@ -213,7 +213,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi return "sql.NullTime" case "pg_catalog.time": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Time" } if notNull { @@ -234,7 +234,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi return "sql.NullTime" case "pg_catalog.timestamp", "timestamp": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Timestamp" } if notNull { @@ -246,7 +246,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi return "sql.NullTime" case "pg_catalog.timestamptz", "timestamptz": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Timestamptz" } if notNull { @@ -264,13 +264,13 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*string" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Text" } return "sql.NullString" case "uuid": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.UUID" } if notNull { @@ -283,7 +283,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "inet": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: if notNull { return "netip.Addr" } @@ -298,7 +298,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "cidr": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: if notNull { return "netip.Prefix" } @@ -313,7 +313,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "macaddr", "macaddr8": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "net.HardwareAddr" case opts.SQLDriverPGXV4: return "pgtype.Macaddr" @@ -335,13 +335,13 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*string" } - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Text" } return "sql.NullString" case "interval", "pg_catalog.interval": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Interval" } if notNull { @@ -356,7 +356,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Daterange" - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Range[pgtype.Date]" default: return "interface{}" @@ -364,7 +364,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "datemultirange": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Date]]" default: return "interface{}" @@ -374,7 +374,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Tsrange" - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Range[pgtype.Timestamp]" default: return "interface{}" @@ -382,7 +382,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "tsmultirange": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Timestamp]]" default: return "interface{}" @@ -392,7 +392,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Tstzrange" - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Range[pgtype.Timestamptz]" default: return "interface{}" @@ -400,7 +400,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "tstzmultirange": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Timestamptz]]" default: return "interface{}" @@ -410,7 +410,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Numrange" - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Range[pgtype.Numeric]" default: return "interface{}" @@ -418,7 +418,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "nummultirange": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Numeric]]" default: return "interface{}" @@ -428,7 +428,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Int4range" - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Range[pgtype.Int4]" default: return "interface{}" @@ -436,7 +436,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "int4multirange": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Int4]]" default: return "interface{}" @@ -446,7 +446,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Int8range" - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Range[pgtype.Int8]" default: return "interface{}" @@ -454,7 +454,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "int8multirange": switch driver { - case opts.SQLDriverPGXV5: + case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Int8]]" default: return "interface{}" @@ -467,7 +467,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi return "interface{}" case "bit", "varbit", "pg_catalog.bit", "pg_catalog.varbit": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Bits" } if driver == opts.SQLDriverPGXV4 { @@ -475,7 +475,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi } case "cid": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Uint32" } if driver == opts.SQLDriverPGXV4 { @@ -483,7 +483,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi } case "oid": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Uint32" } if driver == opts.SQLDriverPGXV4 { @@ -496,7 +496,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi } case "xid": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { return "pgtype.Uint32" } if driver == opts.SQLDriverPGXV4 { @@ -539,7 +539,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi } case "vector": - if driver == opts.SQLDriverPGXV5 { + if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { if emitPointersForNull { return "*pgvector.Vector" } else { From 46428da7e512d9bbd4ba6581899b68552c05f213 Mon Sep 17 00:00:00 2001 From: Suman De Date: Thu, 19 Mar 2026 17:45:25 +0530 Subject: [PATCH 2/6] refactor parseDriver so that we can reuse the PGXV5 --- internal/codegen/golang/driver.go | 13 ++++ internal/codegen/golang/postgresql_type.go | 80 +++++++++++----------- 2 files changed, 53 insertions(+), 40 deletions(-) diff --git a/internal/codegen/golang/driver.go b/internal/codegen/golang/driver.go index 6112ac12e5..aace60fdad 100644 --- a/internal/codegen/golang/driver.go +++ b/internal/codegen/golang/driver.go @@ -14,3 +14,16 @@ func parseDriver(sqlPackage string) opts.SQLDriver { return opts.SQLDriverLibPQ } } + +func parseDriverPGType(sqlPackage string) opts.SQLDriver { + switch sqlPackage { + case opts.SQLPackagePGXV4: + return opts.SQLDriverPGXV4 + case opts.SQLPackagePGXV5: + return opts.SQLDriverPGXV5 + case opts.SQLPackageYugaBytePGXV5: + return opts.SQLDriverPGXV5 + default: + return opts.SQLDriverLibPQ + } +} diff --git a/internal/codegen/golang/postgresql_type.go b/internal/codegen/golang/postgresql_type.go index cc830c3752..4d585bc0c6 100644 --- a/internal/codegen/golang/postgresql_type.go +++ b/internal/codegen/golang/postgresql_type.go @@ -37,7 +37,7 @@ func parseIdentifierString(name string) (*plugin.Identifier, error) { func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string { columnType := sdk.DataType(col.Type) notNull := col.NotNull || col.IsArray - driver := parseDriver(options.SqlPackage) + driver := parseDriverPGType(options.SqlPackage) emitPointersForNull := driver.IsPGX() && options.EmitPointersForNullTypes switch columnType { @@ -48,7 +48,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int32" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Int4" } return "sql.NullInt32" @@ -60,7 +60,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int64" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Int8" } return "sql.NullInt64" @@ -72,7 +72,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int16" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Int2" } return "sql.NullInt16" @@ -84,7 +84,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int32" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Int4" } return "sql.NullInt32" @@ -96,7 +96,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int64" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Int8" } return "sql.NullInt64" @@ -108,7 +108,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*int16" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Int2" } return "sql.NullInt16" @@ -120,7 +120,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*float64" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Float8" } return "sql.NullFloat64" @@ -132,7 +132,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*float32" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Float4" } return "sql.NullFloat64" // TODO: Change to sql.NullFloat32 after updating the go.mod file @@ -160,14 +160,14 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*bool" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Bool" } return "sql.NullBool" case "json", "pg_catalog.json": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "[]byte" case opts.SQLDriverPGXV4: return "pgtype.JSON" @@ -183,7 +183,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "jsonb", "pg_catalog.jsonb": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "[]byte" case opts.SQLDriverPGXV4: return "pgtype.JSONB" @@ -201,7 +201,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi return "[]byte" case "date": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Date" } if notNull { @@ -213,7 +213,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi return "sql.NullTime" case "pg_catalog.time": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Time" } if notNull { @@ -234,7 +234,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi return "sql.NullTime" case "pg_catalog.timestamp", "timestamp": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Timestamp" } if notNull { @@ -246,7 +246,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi return "sql.NullTime" case "pg_catalog.timestamptz", "timestamptz": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Timestamptz" } if notNull { @@ -264,13 +264,13 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*string" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Text" } return "sql.NullString" case "uuid": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.UUID" } if notNull { @@ -283,7 +283,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "inet": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: if notNull { return "netip.Addr" } @@ -298,7 +298,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "cidr": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: if notNull { return "netip.Prefix" } @@ -313,7 +313,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "macaddr", "macaddr8": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "net.HardwareAddr" case opts.SQLDriverPGXV4: return "pgtype.Macaddr" @@ -335,13 +335,13 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi if emitPointersForNull { return "*string" } - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Text" } return "sql.NullString" case "interval", "pg_catalog.interval": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Interval" } if notNull { @@ -356,7 +356,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Daterange" - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Range[pgtype.Date]" default: return "interface{}" @@ -364,7 +364,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "datemultirange": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Date]]" default: return "interface{}" @@ -374,7 +374,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Tsrange" - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Range[pgtype.Timestamp]" default: return "interface{}" @@ -382,7 +382,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "tsmultirange": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Timestamp]]" default: return "interface{}" @@ -392,7 +392,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Tstzrange" - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Range[pgtype.Timestamptz]" default: return "interface{}" @@ -400,7 +400,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "tstzmultirange": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Timestamptz]]" default: return "interface{}" @@ -410,7 +410,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Numrange" - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Range[pgtype.Numeric]" default: return "interface{}" @@ -418,7 +418,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "nummultirange": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Numeric]]" default: return "interface{}" @@ -428,7 +428,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Int4range" - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Range[pgtype.Int4]" default: return "interface{}" @@ -436,7 +436,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "int4multirange": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Int4]]" default: return "interface{}" @@ -446,7 +446,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi switch driver { case opts.SQLDriverPGXV4: return "pgtype.Int8range" - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Range[pgtype.Int8]" default: return "interface{}" @@ -454,7 +454,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi case "int8multirange": switch driver { - case opts.SQLDriverPGXV5, opts.SQLDriverYugaBytePGXV5: + case opts.SQLDriverPGXV5: return "pgtype.Multirange[pgtype.Range[pgtype.Int8]]" default: return "interface{}" @@ -467,7 +467,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi return "interface{}" case "bit", "varbit", "pg_catalog.bit", "pg_catalog.varbit": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Bits" } if driver == opts.SQLDriverPGXV4 { @@ -475,7 +475,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi } case "cid": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Uint32" } if driver == opts.SQLDriverPGXV4 { @@ -483,7 +483,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi } case "oid": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Uint32" } if driver == opts.SQLDriverPGXV4 { @@ -496,7 +496,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi } case "xid": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { return "pgtype.Uint32" } if driver == opts.SQLDriverPGXV4 { @@ -539,7 +539,7 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi } case "vector": - if driver == opts.SQLDriverPGXV5 || driver == opts.SQLDriverYugaBytePGXV5 { + if driver == opts.SQLDriverPGXV5 { if emitPointersForNull { return "*pgvector.Vector" } else { From ece0a7e489c82694518985ebbd645dc12c3bac3a Mon Sep 17 00:00:00 2001 From: Suman De Date: Thu, 19 Mar 2026 18:15:10 +0530 Subject: [PATCH 3/6] refactor --- internal/codegen/golang/driver.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/codegen/golang/driver.go b/internal/codegen/golang/driver.go index aace60fdad..9b27255ae3 100644 --- a/internal/codegen/golang/driver.go +++ b/internal/codegen/golang/driver.go @@ -19,9 +19,7 @@ func parseDriverPGType(sqlPackage string) opts.SQLDriver { switch sqlPackage { case opts.SQLPackagePGXV4: return opts.SQLDriverPGXV4 - case opts.SQLPackagePGXV5: - return opts.SQLDriverPGXV5 - case opts.SQLPackageYugaBytePGXV5: + case opts.SQLPackagePGXV5, opts.SQLPackageYugaBytePGXV5: return opts.SQLDriverPGXV5 default: return opts.SQLDriverLibPQ From 520e3018b27a8deda4453dd19753a353749736df Mon Sep 17 00:00:00 2001 From: Suman De Date: Thu, 19 Mar 2026 20:01:59 +0530 Subject: [PATCH 4/6] docs: clarify the function need --- internal/codegen/golang/driver.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/codegen/golang/driver.go b/internal/codegen/golang/driver.go index 9b27255ae3..027481a900 100644 --- a/internal/codegen/golang/driver.go +++ b/internal/codegen/golang/driver.go @@ -15,6 +15,9 @@ func parseDriver(sqlPackage string) opts.SQLDriver { } } +// custom packages based on pgx/v5 (e.g., YugabyteDB smart drivers) should return +// only the original driver when determining columnType, refer to the postgresType func. + func parseDriverPGType(sqlPackage string) opts.SQLDriver { switch sqlPackage { case opts.SQLPackagePGXV4: From b24def782b4781485c67bc637327275f377a3c60 Mon Sep 17 00:00:00 2001 From: Suman De Date: Thu, 19 Mar 2026 20:08:33 +0530 Subject: [PATCH 5/6] go fmt --- internal/codegen/golang/driver.go | 1 - internal/config/config.go | 4 ++-- internal/engine/clickhouse/convert.go | 4 ++-- internal/engine/clickhouse/parse.go | 6 +++--- internal/engine/sqlite/convert.go | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/codegen/golang/driver.go b/internal/codegen/golang/driver.go index 027481a900..9ef69c0737 100644 --- a/internal/codegen/golang/driver.go +++ b/internal/codegen/golang/driver.go @@ -17,7 +17,6 @@ func parseDriver(sqlPackage string) opts.SQLDriver { // custom packages based on pgx/v5 (e.g., YugabyteDB smart drivers) should return // only the original driver when determining columnType, refer to the postgresType func. - func parseDriverPGType(sqlPackage string) opts.SQLDriver { switch sqlPackage { case opts.SQLPackagePGXV4: diff --git a/internal/config/config.go b/internal/config/config.go index d3e610ef05..717259684a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -125,8 +125,8 @@ type SQL struct { // AnalyzerDatabase represents the database analyzer setting. // It can be a boolean (true/false) or the string "only" for database-only mode. type AnalyzerDatabase struct { - value *bool // nil means not set, true/false for boolean values - isOnly bool // true when set to "only" + value *bool // nil means not set, true/false for boolean values + isOnly bool // true when set to "only" } // IsEnabled returns true if the database analyzer should be used. diff --git a/internal/engine/clickhouse/convert.go b/internal/engine/clickhouse/convert.go index ba2817e2bb..1db0fee49e 100644 --- a/internal/engine/clickhouse/convert.go +++ b/internal/engine/clickhouse/convert.go @@ -485,8 +485,8 @@ func (c *cc) convertFunctionCall(n *chast.FunctionCall) *ast.FuncCall { Funcname: &ast.List{ Items: []ast.Node{&ast.String{Str: n.Name}}, }, - Location: n.Pos().Offset, - AggDistinct: n.Distinct, + Location: n.Pos().Offset, + AggDistinct: n.Distinct, } // Convert arguments diff --git a/internal/engine/clickhouse/parse.go b/internal/engine/clickhouse/parse.go index 282089f31d..a0f851e175 100644 --- a/internal/engine/clickhouse/parse.go +++ b/internal/engine/clickhouse/parse.go @@ -57,8 +57,8 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { // https://clickhouse.com/docs/en/sql-reference/syntax#comments func (p *Parser) CommentSyntax() source.CommentSyntax { return source.CommentSyntax{ - Dash: true, // -- comment - SlashStar: true, // /* comment */ - Hash: true, // # comment (ClickHouse supports this) + Dash: true, // -- comment + SlashStar: true, // /* comment */ + Hash: true, // # comment (ClickHouse supports this) } } diff --git a/internal/engine/sqlite/convert.go b/internal/engine/sqlite/convert.go index e9868f5be6..7c6a4ba269 100644 --- a/internal/engine/sqlite/convert.go +++ b/internal/engine/sqlite/convert.go @@ -826,7 +826,7 @@ func (c *cc) convertUnaryExpr(n *parser.Expr_unaryContext) ast.Node { if opCtx.MINUS() != nil { // Negative number: -expr return &ast.A_Expr{ - Name: &ast.List{Items: []ast.Node{&ast.String{Str: "-"}}}, + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "-"}}}, Rexpr: expr, } } @@ -837,7 +837,7 @@ func (c *cc) convertUnaryExpr(n *parser.Expr_unaryContext) ast.Node { if opCtx.TILDE() != nil { // Bitwise NOT: ~expr return &ast.A_Expr{ - Name: &ast.List{Items: []ast.Node{&ast.String{Str: "~"}}}, + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "~"}}}, Rexpr: expr, } } From ebf9ad7559d19c5159e734d82b7fe885f8596af5 Mon Sep 17 00:00:00 2001 From: Suman De Date: Thu, 19 Mar 2026 20:24:39 +0530 Subject: [PATCH 6/6] refactor: proper sql_package --- internal/codegen/golang/opts/enum.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/codegen/golang/opts/enum.go b/internal/codegen/golang/opts/enum.go index fc199c0b47..83816dbd6a 100644 --- a/internal/codegen/golang/opts/enum.go +++ b/internal/codegen/golang/opts/enum.go @@ -8,7 +8,7 @@ const ( SQLPackagePGXV4 string = "pgx/v4" SQLPackagePGXV5 string = "pgx/v5" SQLPackageStandard string = "database/sql" - SQLPackageYugaBytePGXV5 string = "yb/pgx/v5" + SQLPackageYugaBytePGXV5 string = "yugabyte/pgx/v5" ) var validPackages = map[string]struct{}{