Skip to content

Commit

Permalink
update deps (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxwebdev authored Jul 8, 2023
1 parent ef692bf commit 5b61cd5
Show file tree
Hide file tree
Showing 75 changed files with 9,946 additions and 5,068 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.1"
var version = "v0.2.2"

func main() {
logger := logger.New()
Expand Down
31 changes: 18 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ require (
github.com/jinzhu/inflection v1.0.0
github.com/lib/pq v1.10.9
github.com/mattn/go-sqlite3 v1.14.17
github.com/pingcap/tidb/parser v0.0.0-20230224142707-1d2040a2abb1
github.com/pingcap/tidb/parser v0.0.0-20220725134311-c80026e61f00
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/tkcrm/modules v0.0.0-20230308042354-885154fb5ff9
golang.org/x/sync v0.2.0
golang.org/x/tools v0.9.3
google.golang.org/protobuf v1.30.0
github.com/tkcrm/modules v0.0.0-20230625215006-4020c7ef0b78
golang.org/x/sync v0.3.0
golang.org/x/tools v0.11.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -30,14 +30,19 @@ require (

require (
github.com/cristalhq/flagx v0.4.0
github.com/google/cel-go v0.16.0
github.com/jackc/pgx/v5 v5.4.1
github.com/stretchr/testify v1.8.4
)

require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.10.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
golang.org/x/net v0.12.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
)

require (
Expand All @@ -63,11 +68,11 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/grpc v1.55.0
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/grpc v1.56.2
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)
70 changes: 40 additions & 30 deletions go.sum

Large diffs are not rendered by default.

53 changes: 41 additions & 12 deletions pkg/sqlc/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import (

func init() {
uploadCmd.Flags().BoolP("dry-run", "", false, "dump upload request (default: false)")
initCmd.Flags().BoolP("v1", "", false, "generate v1 config yaml file")
initCmd.Flags().BoolP("v2", "", true, "generate v2 config yaml file")
initCmd.MarkFlagsMutuallyExclusive("v1", "v2")
}

// Do runs the command logic.
Expand All @@ -34,19 +37,20 @@ func Do(args []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) int
rootCmd.PersistentFlags().StringP("file", "f", "", "specify an alternate config file (default: sqlc.yaml)")
rootCmd.PersistentFlags().BoolP("experimental", "x", false, "DEPRECATED: enable experimental features (default: false)")
rootCmd.PersistentFlags().Bool("no-remote", false, "disable remote execution (default: false)")
rootCmd.PersistentFlags().Bool("no-database", false, "disable database connections (default: false)")

rootCmd.AddCommand(checkCmd)
rootCmd.AddCommand(diffCmd)
rootCmd.AddCommand(genCmd)
rootCmd.AddCommand(initCmd)
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(uploadCmd)
rootCmd.AddCommand(NewCmdVet())

rootCmd.SetArgs(args)
rootCmd.SetIn(stdin)
rootCmd.SetOut(stdout)
rootCmd.SetErr(stderr)
rootCmd.SilenceErrors = true

ctx := context.Background()
if debug.Debug.Trace != "" {
Expand Down Expand Up @@ -76,9 +80,9 @@ var versionCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
defer trace.StartRegion(cmd.Context(), "version").End()
if version == "" {
fmt.Printf("%s\n", info.Version)
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", info.Version)
} else {
fmt.Printf("%s\n", version)
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", version)
}
return nil
},
Expand All @@ -88,6 +92,17 @@ var initCmd = &cobra.Command{
Use: "init",
Short: "Create an empty sqlc.yaml settings file",
RunE: func(cmd *cobra.Command, args []string) error {
useV1, err := cmd.Flags().GetBool("v1")
if err != nil {
return err
}
var yamlConfig interface{}
if useV1 {
yamlConfig = config.V1GenerateSettings{Version: "1"}
} else {
yamlConfig = config.Config{Version: "2"}
}

defer trace.StartRegion(cmd.Context(), "init").End()
file := "sqlc.yaml"
if f := cmd.Flag("file"); f != nil && f.Changed {
Expand All @@ -97,29 +112,43 @@ var initCmd = &cobra.Command{
}
}
if _, err := os.Stat(file); !os.IsNotExist(err) {
fmt.Printf("%s is already created\n", file)
return nil
}
blob, err := yaml.Marshal(config.V1GenerateSettings{Version: "1"})
blob, err := yaml.Marshal(yamlConfig)
if err != nil {
return err
}
return os.WriteFile(file, blob, 0644)
err = os.WriteFile(file, blob, 0644)
if err != nil {
return err
}
configDoc := "https://docs.sqlc.dev/en/stable/reference/config.html"
fmt.Printf(
"%s is added. Please visit %s to learn more about configuration\n",
file,
configDoc,
)
return nil
},
}

type Env struct {
DryRun bool
Debug opts.Debug
NoRemote bool
DryRun bool
Debug opts.Debug
NoRemote bool
NoDatabase bool
}

func ParseEnv(c *cobra.Command) Env {
dr := c.Flag("dry-run")
nr := c.Flag("no-remote")
nodb := c.Flag("no-database")
return Env{
DryRun: dr != nil && dr.Changed,
Debug: opts.DebugFromEnv(),
NoRemote: nr != nil && nr.Value.String() == "true",
DryRun: dr != nil && dr.Changed,
Debug: opts.DebugFromEnv(),
NoRemote: nr != nil && nr.Value.String() == "true",
NoDatabase: nodb != nil && nodb.Value.String() == "true",
}
}

Expand Down Expand Up @@ -166,7 +195,7 @@ var genCmd = &cobra.Command{
dir, name := getConfigPath(stderr, cmd.Flag("file"))
output, err := Generate(cmd.Context(), ParseEnv(cmd), dir, name, stderr)
if err != nil {
return err
os.Exit(1)
}
defer trace.StartRegion(cmd.Context(), "writefiles").End()
for filename, source := range output {
Expand Down
8 changes: 4 additions & 4 deletions pkg/sqlc/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ func readConfig(stderr io.Writer, dir, filename string) (string, *config.Config,
if err != nil {
switch err {
case config.ErrMissingVersion:
fmt.Fprintf(stderr, errMessageNoVersion)
fmt.Fprint(stderr, errMessageNoVersion)
case config.ErrUnknownVersion:
fmt.Fprintf(stderr, errMessageUnknownVersion)
fmt.Fprint(stderr, errMessageUnknownVersion)
case config.ErrNoPackages:
fmt.Fprintf(stderr, errMessageNoPackages)
fmt.Fprint(stderr, errMessageNoPackages)
}
fmt.Fprintf(stderr, "error parsing %s: %s\n", base, err)
return "", nil, err
Expand Down Expand Up @@ -257,7 +257,7 @@ func Generate(ctx context.Context, e Env, dir, filename string, stderr io.Writer
return nil, err
}
if errored {
for i := range stderrs {
for i, _ := range stderrs {
if _, err := io.Copy(stderr, &stderrs[i]); err != nil {
return nil, err
}
Expand Down
26 changes: 16 additions & 10 deletions pkg/sqlc/cmd/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
"github.com/tkcrm/pgxgen/pkg/sqlc/sql/catalog"
)

func pluginOverride(o config.Override) *plugin.Override {
func pluginOverride(r *compiler.Result, o config.Override) *plugin.Override {
var column string
var table plugin.Identifier

if o.Column != "" {
colParts := strings.Split(o.Column, ".")
switch len(colParts) {
case 2:
table.Schema = "public"
table.Schema = r.Catalog.DefaultSchema
table.Name = colParts[0]
column = colParts[1]
case 3:
Expand All @@ -37,17 +37,18 @@ func pluginOverride(o config.Override) *plugin.Override {
CodeType: "", // FIXME
DbType: o.DBType,
Nullable: o.Nullable,
Unsigned: o.Unsigned,
Column: o.Column,
ColumnName: column,
Table: &table,
GoType: pluginGoType(o),
}
}

func pluginSettings(cs config.CombinedSettings) *plugin.Settings {
func pluginSettings(r *compiler.Result, cs config.CombinedSettings) *plugin.Settings {
var over []*plugin.Override
for _, o := range cs.Overrides {
over = append(over, pluginOverride(o))
over = append(over, pluginOverride(r, o))
}
return &plugin.Settings{
Version: cs.Global.Version,
Expand Down Expand Up @@ -83,6 +84,7 @@ func pluginGoCode(s config.SQLGo) *plugin.GoCode {
return &plugin.GoCode{
EmitInterface: s.EmitInterface,
EmitJsonTags: s.EmitJSONTags,
JsonTagsIdUppercase: s.JsonTagsIDUppercase,
EmitDbTags: s.EmitDBTags,
EmitPreparedQueries: s.EmitPreparedQueries,
EmitExactTableNames: s.EmitExactTableNames,
Expand All @@ -106,14 +108,15 @@ func pluginGoCode(s config.SQLGo) *plugin.GoCode {
OutputFilesSuffix: s.OutputFilesSuffix,
InflectionExcludeTableNames: s.InflectionExcludeTableNames,
QueryParameterLimit: s.QueryParameterLimit,
OmitUnusedStructs: s.OmitUnusedStructs,
}
}

func pluginGoType(o config.Override) *plugin.ParsedGoType {
// Note that there is a slight mismatch between this and the
// proto api. The GoType on the override is the unparsed type,
// which could be a qualified path or an object, as per
// https://docs.sqlc.dev/en/latest/reference/config.html#renaming-struct-fields
// https://docs.sqlc.dev/en/v1.18.0/reference/config.html#type-overriding
return &plugin.ParsedGoType{
ImportPath: o.GoImportPath,
Package: o.GoPackage,
Expand Down Expand Up @@ -166,10 +169,11 @@ func pluginCatalog(c *catalog.Catalog) *plugin.Catalog {
Schema: c.Type.Schema,
Name: c.Type.Name,
},
Comment: c.Comment,
NotNull: c.IsNotNull,
IsArray: c.IsArray,
Length: int32(l),
Comment: c.Comment,
NotNull: c.IsNotNull,
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
Length: int32(l),
Table: &plugin.Identifier{
Catalog: t.Rel.Catalog,
Schema: t.Rel.Schema,
Expand Down Expand Up @@ -243,8 +247,10 @@ func pluginQueryColumn(c *compiler.Column) *plugin.Column {
}
out := &plugin.Column{
Name: c.Name,
OriginalName: c.OriginalName,
Comment: c.Comment,
NotNull: c.NotNull,
Unsigned: c.Unsigned,
IsArray: c.IsArray,
Length: int32(l),
IsNamedParam: c.IsNamedParam,
Expand Down Expand Up @@ -292,7 +298,7 @@ func pluginQueryParam(p compiler.Parameter) *plugin.Parameter {

func codeGenRequest(r *compiler.Result, settings config.CombinedSettings) *plugin.CodeGenRequest {
return &plugin.CodeGenRequest{
Settings: pluginSettings(settings),
Settings: pluginSettings(r, settings),
Catalog: pluginCatalog(r.Catalog),
Queries: pluginQueries(r),
SqlcVersion: info.Version,
Expand Down
Loading

0 comments on commit 5b61cd5

Please sign in to comment.