Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var initCmd = &cobra.Command{
if err != nil {
return err
}
var yamlConfig interface{}
var yamlConfig any
if useV1 {
yamlConfig = config.V1GenerateSettings{Version: "1"}
} else {
Expand Down
1 change: 0 additions & 1 deletion internal/cmd/createdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func CreateDB(ctx context.Context, dir, filename, querySetName string, o *Option
var queryset *config.SQL
var count int
for _, sql := range conf.SQL {
sql := sql
if querySetName != "" && sql.Name != querySetName {
continue
}
Expand Down
20 changes: 10 additions & 10 deletions internal/codegen/golang/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,23 @@ func toPascalCase(s string) string {
}

func toCamelInitCase(name string, initUpper bool) string {
out := ""
var out strings.Builder
for i, p := range strings.Split(name, "_") {
if !initUpper && i == 0 {
out += p
out.WriteString(p)
continue
}
if p == "id" {
out += "ID"
out.WriteString("ID")
} else {
out += strings.Title(p)
out.WriteString(strings.Title(p))
}
}
return out
return out.String()
}

func toJsonCamelCase(name string, idUppercase bool) string {
out := ""
var out strings.Builder
idStr := "Id"

if idUppercase {
Expand All @@ -122,16 +122,16 @@ func toJsonCamelCase(name string, idUppercase bool) string {

for i, p := range strings.Split(name, "_") {
if i == 0 {
out += p
out.WriteString(p)
continue
}
if p == "id" {
out += idStr
out.WriteString(idStr)
} else {
out += strings.Title(p)
out.WriteString(strings.Title(p))
}
}
return out
return out.String()
}

func toLowerCase(str string) string {
Expand Down
7 changes: 3 additions & 4 deletions internal/codegen/golang/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"go/format"
"slices"
"strings"
"text/template"

Expand Down Expand Up @@ -344,10 +345,8 @@ func usesCopyFrom(queries []Query) bool {

func usesBatch(queries []Query) bool {
for _, q := range queries {
for _, cmd := range []string{metadata.CmdBatchExec, metadata.CmdBatchMany, metadata.CmdBatchOne} {
if q.Cmd == cmd {
return true
}
if slices.Contains([]string{metadata.CmdBatchExec, metadata.CmdBatchMany, metadata.CmdBatchOne}, q.Cmd) {
return true
}
}
return false
Expand Down
9 changes: 3 additions & 6 deletions internal/codegen/golang/go_type.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package golang

import (
"maps"
"strings"

"github.com/sqlc-dev/sqlc/internal/codegen/golang/opts"
Expand All @@ -15,9 +16,7 @@ func addExtraGoStructTags(tags map[string]string, req *plugin.GenerateRequest, o
continue
}
if override.MatchesColumn(col) {
for k, v := range oride.GoType.StructTags {
tags[k] = v
}
maps.Copy(tags, oride.GoType.StructTags)
continue
}
if !override.Matches(col.Table, req.Catalog.DefaultSchema) {
Expand All @@ -33,9 +32,7 @@ func addExtraGoStructTags(tags map[string]string, req *plugin.GenerateRequest, o
continue
}
// Add the extra tags.
for k, v := range oride.GoType.StructTags {
tags[k] = v
}
maps.Copy(tags, oride.GoType.StructTags)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/golang/opts/go_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (o *GoType) UnmarshalJSON(data []byte) error {
return nil
}

func (o *GoType) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (o *GoType) UnmarshalYAML(unmarshal func(any) error) error {
var spec string
if err := unmarshal(&spec); err == nil {
*o = GoType{Spec: spec}
Expand Down
10 changes: 5 additions & 5 deletions internal/codegen/golang/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,17 @@ func paramName(p *plugin.Parameter) string {
}

func argName(name string) string {
out := ""
var out strings.Builder
for i, p := range strings.Split(name, "_") {
if i == 0 {
out += strings.ToLower(p)
out.WriteString(strings.ToLower(p))
} else if p == "id" {
out += "ID"
out.WriteString("ID")
} else {
out += strings.Title(p)
out.WriteString(strings.Title(p))
}
}
return out
return out.String()
}

func buildQueries(req *plugin.GenerateRequest, options *opts.Options, structs []Struct) ([]Query, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/golang/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func StructName(name string, options *opts.Options) string {
return rune('_')
}, name)

for _, p := range strings.Split(name, "_") {
for p := range strings.SplitSeq(name, "_") {
if _, found := options.InitialismsMap[p]; found {
out += strings.ToUpper(p)
} else {
Expand Down
1 change: 0 additions & 1 deletion internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro

var tables []*Table
for _, item := range list.Items {
item := item
switch n := item.(type) {

case *ast.RangeFunction:
Expand Down
10 changes: 5 additions & 5 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (p *Paths) UnmarshalJSON(data []byte) error {
return nil
}

func (p *Paths) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (p *Paths) UnmarshalYAML(unmarshal func(any) error) error {
out := []string{}
if sliceErr := unmarshal(&out); sliceErr != nil {
var ele string
Expand All @@ -61,7 +61,7 @@ type Config struct {
Cloud Cloud `json:"cloud" yaml:"cloud"`
Servers []Server `json:"servers" yaml:"servers"`
SQL []SQL `json:"sql" yaml:"sql"`
Overrides Overrides `json:"overrides,omitempty" yaml:"overrides"`
Overrides Overrides `json:"overrides" yaml:"overrides"`
Plugins []Plugin `json:"plugins" yaml:"plugins"`
Rules []Rule `json:"rules" yaml:"rules"`
Options map[string]yaml.Node `json:"options" yaml:"options"`
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -166,7 +166,7 @@ func (a *AnalyzerDatabase) UnmarshalJSON(data []byte) error {
return errors.New("analyzer.database must be true, false, or \"only\"")
}

func (a *AnalyzerDatabase) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (a *AnalyzerDatabase) UnmarshalYAML(unmarshal func(any) error) error {
// Try to unmarshal as boolean first
var b bool
if err := unmarshal(&b); err == nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/config/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"gopkg.in/yaml.v3"
)

func gen(n *yaml.Node) (interface{}, error) {
func gen(n *yaml.Node) (any, error) {
switch n.Kind {

case yaml.MappingNode:
nn := map[string]interface{}{}
nn := map[string]any{}
for i, _ := range n.Content {
if i%2 == 0 {
k := n.Content[i]
Expand All @@ -26,7 +26,7 @@ func gen(n *yaml.Node) (interface{}, error) {
return nn, nil

case yaml.SequenceNode:
nn := []interface{}{}
nn := []any{}
for i, _ := range n.Content {
v, err := gen(n.Content[i])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/dbmanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (m *ManagedClient) CreateDatabase(ctx context.Context, req *CreateDatabaseR
uri.Path = "/" + name

key := uri.String()
_, err, _ = flight.Do(key, func() (interface{}, error) {
_, err, _ = flight.Do(key, func() (any, error) {
// TODO: Use a parameterized query
row := pool.QueryRow(ctx,
fmt.Sprintf(`SELECT datname FROM pg_database WHERE datname = '%s'`, name))
Expand Down
2 changes: 1 addition & 1 deletion internal/debug/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {
}
}

func Dump(n ...interface{}) {
func Dump(n ...any) {
if Active {
spew.Dump(n)
}
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

func TestValidSchema(t *testing.T) {
for _, replay := range FindTests(t, "testdata", "base") {
replay := replay // https://golang.org/doc/faq#closures_and_goroutines

if replay.Exec != nil {
if replay.Exec.Meta.InvalidSchema {
Expand All @@ -32,7 +31,6 @@ func TestValidSchema(t *testing.T) {
}

for j, pkg := range conf.SQL {
j, pkg := j, pkg
switch pkg.Engine {
case config.EnginePostgreSQL:
// pass
Expand Down
3 changes: 0 additions & 3 deletions internal/endtoend/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ func TestReplay(t *testing.T) {
}

for name, testctx := range contexts {
name := name
testctx := testctx

if !testctx.Enabled() {
continue
Expand Down Expand Up @@ -354,7 +352,6 @@ func cmpDirectory(t *testing.T, dir string, actual map[string]string) {
if !cmp.Equal(expected, actual, opts...) {
t.Errorf("%s contents differ", dir)
for name, contents := range expected {
name := name
if actual[name] == "" {
t.Errorf("%s is empty", name)
return
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type sqlFormatter interface {
func TestFormat(t *testing.T) {
t.Parallel()
for _, tc := range FindTests(t, "testdata", "base") {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
// Parse the config file to determine the engine
configPath := filepath.Join(tc.Path, tc.ConfigName)
Expand Down Expand Up @@ -145,7 +144,6 @@ func TestFormat(t *testing.T) {
}

for i, stmt := range stmts {
stmt := stmt
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
// Extract the original query text using statement location and length
start := stmt.Raw.StmtLocation
Expand Down
4 changes: 3 additions & 1 deletion internal/engine/postgresql/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import "github.com/sqlc-dev/sqlc/internal/sql/catalog"

// toPointer converts an int to a pointer without a temporary
// variable at the call-site, and is used by the generated schemas
//
//go:fix inline
func toPointer(x int) *int {
return &x
return new(x)
}

func NewCatalog() *catalog.Catalog {
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/sqlite/analyzer/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (a *Analyzer) Analyze(ctx context.Context, n ast.Node, query string, migrat

// Get column information
colCount := stmt.ColumnCount()
for i := 0; i < colCount; i++ {
for i := range colCount {
name := stmt.ColumnName(i)
declType := stmt.ColumnDeclType(i)
tableName := stmt.ColumnTableName(i)
Expand Down Expand Up @@ -249,7 +249,7 @@ func (a *Analyzer) GetColumnNames(ctx context.Context, query string) ([]string,

colCount := stmt.ColumnCount()
columns := make([]string, colCount)
for i := 0; i < colCount; i++ {
for i := range colCount {
columns[i] = stmt.ColumnName(i)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/engine/sqlite/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type errorListener struct {
err string
}

func (el *errorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) {
func (el *errorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol any, line, column int, msg string, e antlr.RecognitionException) {
el.err = msg
}

Expand Down
2 changes: 1 addition & 1 deletion internal/ext/wasm/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *Runner) loadAndCompile(ctx context.Context) (*runtimeAndCode, error) {
if err != nil {
return nil, err
}
value, err, _ := flight.Do(expected, func() (interface{}, error) {
value, err, _ := flight.Do(expected, func() (any, error) {
return r.loadAndCompileWASM(ctx, cacheDir, expected)
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/metadata/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func validateQueryName(name string) error {
}

func ParseQueryNameAndType(t string, commentStyle CommentSyntax) (string, string, error) {
for _, line := range strings.Split(t, "\n") {
for line := range strings.SplitSeq(t, "\n") {
var prefix string
if strings.HasPrefix(line, "--") {
if !commentStyle.Dash {
Expand Down
2 changes: 1 addition & 1 deletion internal/opts/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func DebugFromString(val string) Debug {
if val == "" {
return d
}
for _, pair := range strings.Split(val, ",") {
for pair := range strings.SplitSeq(val, ",") {
pair = strings.TrimSpace(pair)
switch {
case pair == "dumpast=1":
Expand Down
2 changes: 1 addition & 1 deletion internal/opts/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func ExperimentFromString(val string) Experiment {
return e
}

for _, name := range strings.Split(val, ",") {
for name := range strings.SplitSeq(val, ",") {
name = strings.TrimSpace(name)
if name == "" {
continue
Expand Down
Loading
Loading