Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address comments
  • Loading branch information
kyleconroy committed Oct 12, 2023
commit 770837d0cf5c73c0ed8675f4b350f5c42001c99e
3 changes: 2 additions & 1 deletion examples/authors/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ sql:
queries: postgresql/query.sql
engine: postgresql
database:
analyzer: false
managed: true
analyzer:
database: false
rules:
- sqlc/db-prepare
- postgresql-query-too-costly
Expand Down
6 changes: 4 additions & 2 deletions examples/booktest/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"queries": "postgresql/query.sql",
"engine": "postgresql",
"database": {
"managed": true,
"analyzer": false
"managed": true
},
"analyzer": {
"database": false
},
"rules": [
"sqlc/db-prepare"
Expand Down
4 changes: 3 additions & 1 deletion examples/jets/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"queries": "postgresql/query-building.sql",
"engine": "postgresql",
"database": {
"analyzer": false,
"managed": true
},
"analyzer": {
"database": false
},
"rules": [
"sqlc/db-prepare"
]
Expand Down
8 changes: 5 additions & 3 deletions examples/ondeck/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"queries": "postgresql/query",
"engine": "postgresql",
"database": {
"managed": true,
"analyzer": false
"managed": true
},
"analyzer": {
"database": false
},
"rules": [
"sqlc/db-prepare"
Expand All @@ -22,7 +24,7 @@
"emit_interface": true
},
{
"path": "mysql",
"path": "mysql",
"name": "ondeck",
"schema": "mysql/schema",
"queries": "mysql/query",
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err
c.parser = postgresql.NewParser()
c.catalog = postgresql.NewCatalog()
if conf.Database != nil {
if conf.Database.Analyzer == nil || *conf.Database.Analyzer {
if conf.Analyzer.Database == nil || *conf.Analyzer.Database {
c.analyzer = pganalyze.New(c.client, *conf.Database)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package compiler

import (
"fmt"
"log/slog"
"strconv"

"github.com/sqlc-dev/sqlc/internal/sql/ast"
Expand All @@ -10,7 +11,6 @@ import (
"github.com/sqlc-dev/sqlc/internal/sql/named"
"github.com/sqlc-dev/sqlc/internal/sql/rewrite"
"github.com/sqlc-dev/sqlc/internal/sql/sqlerr"
"golang.org/x/exp/slog"
)

func dataType(n *ast.TypeName) string {
Expand Down
10 changes: 7 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ type Config struct {
}

type Database struct {
URI string `json:"uri" yaml:"uri"`
Managed bool `json:"managed" yaml:"managed"`
Analyzer *bool `json:"analyzer" yaml:"analyzer"`
URI string `json:"uri" yaml:"uri"`
Managed bool `json:"managed" yaml:"managed"`
}

type Cloud struct {
Expand Down Expand Up @@ -112,6 +111,11 @@ type SQL struct {
Gen SQLGen `json:"gen" yaml:"gen"`
Codegen []Codegen `json:"codegen" yaml:"codegen"`
Rules []string `json:"rules" yaml:"rules"`
Analyzer Analyzer `json:"analyzer" yaml:"analyzer"`
}

type Analyzer struct {
Database *bool `json:"database" yaml:"database"`
}

// TODO: Figure out a better name for this
Expand Down
1 change: 1 addition & 0 deletions internal/config/v_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type v1PackageSettings struct {
QueryParameterLimit *int32 `json:"query_parameter_limit,omitempty" yaml:"query_parameter_limit"`
OmitUnusedStructs bool `json:"omit_unused_structs,omitempty" yaml:"omit_unused_structs"`
Rules []string `json:"rules" yaml:"rules"`
Analyzer Analyzer `json:"analyzer" yaml:"analyzer"`
}

func v1ParseConfig(rd io.Reader) (Config, error) {
Expand Down
8 changes: 8 additions & 0 deletions internal/config/v_one.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
}
}
},
"analyzer": {
"type": "object",
"properties": {
"database": {
"type": "boolean"
}
}
},
"strict_function_checks": {
"type": "boolean"
},
Expand Down
8 changes: 8 additions & 0 deletions internal/config/v_two.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
}
}
},
"analyzer": {
"type": "object",
"properties": {
"database": {
"type": "boolean"
}
}
},
"strict_function_checks": {
"type": "boolean"
},
Expand Down
25 changes: 15 additions & 10 deletions internal/endtoend/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
osexec "os/exec"
"path/filepath"
"slices"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"golang.org/x/exp/slices"

"github.com/sqlc-dev/sqlc/internal/cmd"
"github.com/sqlc-dev/sqlc/internal/config"
Expand Down Expand Up @@ -166,7 +167,7 @@ func TestReplay(t *testing.T) {
}
}

expected := expectedStderr(t, path)
expected := expectedStderr(t, path, name)
opts := cmd.Options{
Env: cmd.Env{
Debug: opts.DebugFromString(args.Env["SQLCDEBUG"]),
Expand Down Expand Up @@ -202,7 +203,6 @@ func TestReplay(t *testing.T) {
}
}
if diff != "" {
t.Log(stderr.String()) // TODO: Remove
t.Fatalf("stderr differed (-want +got):\n%s", diff)
}
})
Expand Down Expand Up @@ -269,15 +269,20 @@ func cmpDirectory(t *testing.T, dir string, actual map[string]string) {
}
}

func expectedStderr(t *testing.T, dir string) string {
func expectedStderr(t *testing.T, dir, testctx string) string {
t.Helper()
path := filepath.Join(dir, "stderr.txt")
if _, err := os.Stat(path); !os.IsNotExist(err) {
blob, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
paths := []string{
filepath.Join(dir, "stderr", fmt.Sprintf("%s.txt", testctx)),
filepath.Join(dir, "stderr.txt"),
}
for _, path := range paths {
if _, err := os.Stat(path); !os.IsNotExist(err) {
blob, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
return string(blob)
}
return string(blob)
}
return ""
}
Expand Down
54 changes: 0 additions & 54 deletions internal/endtoend/testdata/diff_output/stderr.txt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# package querytest
query.sql:1:1: INSERT has more expressions than target columns
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# package querytest
query.sql:3:11: INSERT has more expressions than target columns
1 change: 0 additions & 1 deletion internal/sql/validate/func_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (v *funcCallVisitor) Visit(node ast.Node) astutils.Visitor {
return v
}

// Maybe not necessary now?
if fn.Schema == "sqlc" {
return nil
}
Expand Down