Skip to content

Commit

Permalink
update sqlc (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxwebdev authored Jul 13, 2023
1 parent 5b61cd5 commit 5ff581e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/pgxgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/tkcrm/pgxgen/pkg/logger"
)

var version = "v0.2.2"
var version = "v0.2.3"

func main() {
logger := logger.New()
Expand Down
7 changes: 3 additions & 4 deletions pkg/sqlc/codegen/golang/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,9 @@ func filterUnusedStructs(enums []Enum, structs []Struct, queries []Query) ([]Enu

keepEnums := make([]Enum, 0, len(enums))
for _, enum := range enums {
if _, ok := keepTypes[enum.Name]; ok {
keepEnums = append(keepEnums, enum)
}
if _, ok := keepTypes["Null"+enum.Name]; ok {
_, keep := keepTypes[enum.Name]
_, keepNull := keepTypes["Null"+enum.Name]
if keep || keepNull {
keepEnums = append(keepEnums, enum)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlc/codegen/golang/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func buildImports(settings *plugin.Settings, queries []Query, uses func(string)

for typeName, _ := range pqtypeTypes {
if uses(typeName) {
pkg[ImportSpec{Path: "github.com/tabbed/pqtype"}] = struct{}{}
pkg[ImportSpec{Path: "github.com/sqlc-dev/pqtype"}] = struct{}{}
break
}
}
Expand Down
18 changes: 13 additions & 5 deletions pkg/sqlc/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (c *Compiler) outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, er
targets = n.ReturningList
case *ast.SelectStmt:
targets = n.TargetList
isUnion := len(targets.Items) == 0 && n.Larg != nil

if n.GroupClause != nil {
for _, item := range n.GroupClause.Items {
Expand All @@ -77,7 +78,7 @@ func (c *Compiler) outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, er
if c.conf.StrictOrderBy != nil {
validateOrderBy = *c.conf.StrictOrderBy
}
if validateOrderBy {
if !isUnion && validateOrderBy {
if n.SortClause != nil {
for _, item := range n.SortClause.Items {
sb, ok := item.(*ast.SortBy)
Expand Down Expand Up @@ -110,7 +111,7 @@ func (c *Compiler) outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, er

// For UNION queries, targets is empty and we need to look for the
// columns in Largs.
if len(targets.Items) == 0 && n.Larg != nil {
if isUnion {
return c.outputColumns(qc, n.Larg)
}
case *ast.CallStmt:
Expand Down Expand Up @@ -502,18 +503,25 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
switch n := item.(type) {

case *ast.RangeFunction:
// If the function or table can't be found, don't error out. There
// are many queries that depend on functions unknown to sqlc.
var funcCall *ast.FuncCall
switch f := n.Functions.Items[0].(type) {
case *ast.List:
funcCall = f.Items[0].(*ast.FuncCall)
switch fi := f.Items[0].(type) {
case *ast.FuncCall:
funcCall = fi
case *ast.SQLValueFunction:
continue // TODO handle this correctly
default:
continue
}
case *ast.FuncCall:
funcCall = f
default:
return nil, fmt.Errorf("sourceTables: unsupported function call type %T", n.Functions.Items[0])
}

// If the function or table can't be found, don't error out. There
// are many queries that depend on functions unknown to sqlc.
fn, err := qc.GetFunc(funcCall.Func)
if err != nil {
continue
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlc/info/facts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package info

// When no version is set, return the next bug fix version
// after the most recent tag
const Version = "v1.19.0"
const Version = "v1.19.1"
1 change: 1 addition & 0 deletions pkg/sqlc/sql/astutils/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.

case *ast.In:
a.applyList(n, "List")
a.apply(n, "Sel", nil, n.Sel)

case *ast.List:
// Since item is a slice
Expand Down

0 comments on commit 5ff581e

Please sign in to comment.