diff --git a/internal/codegen/golang/driver.go b/internal/codegen/golang/driver.go index 5e3a533dcc..9ef69c0737 100644 --- a/internal/codegen/golang/driver.go +++ b/internal/codegen/golang/driver.go @@ -8,6 +8,21 @@ 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 + } +} + +// 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: + return opts.SQLDriverPGXV4 + case opts.SQLPackagePGXV5, opts.SQLPackageYugaBytePGXV5: + return opts.SQLDriverPGXV5 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..83816dbd6a 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 = "yugabyte/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..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 { 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, } }