Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
sxwebdev authored Aug 7, 2023
1 parent 5ff581e commit dfb0a62
Show file tree
Hide file tree
Showing 63 changed files with 13,154 additions and 4,562 deletions.
2 changes: 1 addition & 1 deletion cmd/copysqlc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func renameGoPackage(path string) error {

newFileContent := strings.ReplaceAll(
string(fileContent),
"github.com/kyleconroy/sqlc/internal",
"github.com/sqlc-dev/sqlc/internal",
"github.com/tkcrm/pgxgen/pkg/sqlc",
)

Expand Down
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.3"
var version = "v0.2.4"

func main() {
logger := logger.New()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require (

require (
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/bytecodealliance/wasmtime-go/v8 v8.0.0
github.com/bytecodealliance/wasmtime-go/v11 v11.0.0
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/goccy/go-json v0.10.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3d
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/bytecodealliance/wasmtime-go/v8 v8.0.0 h1:jP4sqm2PHgm3+eQ50zCoCdIyQFkIL/Rtkw6TT8OYPFI=
github.com/bytecodealliance/wasmtime-go/v8 v8.0.0/go.mod h1:tgazNLU7xSC2gfRAM8L4WyE+dgs5yp9FF5/tGebEQyM=
github.com/bytecodealliance/wasmtime-go/v11 v11.0.0 h1:SwLgbjbFpQ1tf5vIbWexaZABezBSL8WmzP+foLyi0lE=
github.com/bytecodealliance/wasmtime-go/v11 v11.0.0/go.mod h1:9btfEuCkOP7EDR9a7LqDXrfQ7dtWeGlDHt3buV5UyjY=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
Expand Down
60 changes: 39 additions & 21 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"path/filepath"

"github.com/cristalhq/flagx"
"github.com/tkcrm/pgxgen/pkg/logger"
"gopkg.in/yaml.v2"
)

type Config struct {
Sqlc Sqlc
Pgxgen Pgxgen
Sqlc Sqlc
Pgxgen Pgxgen
loadErrs []error
}

type configFlags struct {
Expand All @@ -29,7 +31,9 @@ func (c *configFlags) Flags() *flag.FlagSet {

// LoadConfig return common config with sqlc and pgxgen data
func LoadConfig(version string) (Config, error) {
var cfg Config
cfg := Config{
loadErrs: make([]error, 0),
}

// parse config flags
var cf configFlags
Expand All @@ -41,32 +45,34 @@ func LoadConfig(version string) (Config, error) {
var sqlcConfig Sqlc
sqlcConfigFile, err := os.ReadFile(cf.sqlcConfigFilePath)
if err != nil {
return cfg, fmt.Errorf("failed to read sqlc config file: %w", err)
}

if err := yaml.Unmarshal(sqlcConfigFile, &sqlcConfig); err != nil {
return cfg, err
}

// validate sqlc config
for _, p := range sqlcConfig.Packages {
if p.Path == "" {
return cfg, fmt.Errorf("undefined path in sqlc.yaml")
cfg.loadErrs = append(cfg.loadErrs, fmt.Errorf("failed to read sqlc config file: %w", err))
} else {
// unmashal yaml to sqlc config struct
if err := yaml.Unmarshal(sqlcConfigFile, &sqlcConfig); err != nil {
return cfg, err
}
if p.Queries == "" {
return cfg, fmt.Errorf("undefined queries in sqlc.yaml")

// validate sqlc config
for _, p := range sqlcConfig.Packages {
if p.Path == "" {
return cfg, fmt.Errorf("undefined path in sqlc.yaml")
}
if p.Queries == "" {
return cfg, fmt.Errorf("undefined queries in sqlc.yaml")
}
}
}

// load pgxgen config
var pgxgenConfig Pgxgen
pgxgenConfigFile, err := os.ReadFile(cf.pgxgenConfigFilePath)
if err != nil {
return cfg, err
}

if err := yaml.Unmarshal(pgxgenConfigFile, &pgxgenConfig); err != nil {
return cfg, err
cfg.loadErrs = append(cfg.loadErrs, fmt.Errorf("failed to read pgxgen config file: %w", err))
} else {
// unmashal yaml to pgxgen config struct
if err := yaml.Unmarshal(pgxgenConfigFile, &pgxgenConfig); err != nil {
return cfg, err
}
}

cfg.Sqlc = sqlcConfig
Expand Down Expand Up @@ -120,3 +126,15 @@ func LoadTestConfig(configsPath string) (Config, error) {

return cfg, nil
}

// CheckErrors check load errors, print them end exit
func (c *Config) CheckErrors(l logger.Logger) {
if len(c.loadErrs) == 0 {
return
}

for _, err := range c.loadErrs {
l.Info(err)
}
os.Exit(1)
}
1 change: 1 addition & 0 deletions internal/crud/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error {
return func(ctx context.Context, args []string) error {
cfg.CheckErrors(l)
return New(l, cfg).Generate(ctx, args)
}
}
1 change: 1 addition & 0 deletions internal/gomodels/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error {
return func(ctx context.Context, args []string) error {
cfg.CheckErrors(l)
return New(l, cfg).Generate(ctx, args)
}
}
1 change: 1 addition & 0 deletions internal/keystone/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error {
return func(ctx context.Context, args []string) error {
cfg.CheckErrors(l)
return New(l, cfg).Generate(ctx, args)
}
}
1 change: 1 addition & 0 deletions internal/sqlc/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error {
return func(ctx context.Context, args []string) error {
cfg.CheckErrors(l)
return New(l, cfg).Generate(ctx, args)
}
}
1 change: 1 addition & 0 deletions internal/typescript/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error {
return func(ctx context.Context, args []string) error {
cfg.CheckErrors(l)
return New(l, cfg).Generate(ctx, args)
}
}
12 changes: 7 additions & 5 deletions pkg/sqlc/cmd/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,12 @@ func pluginCatalog(c *catalog.Catalog) *plugin.Catalog {
Schema: c.Type.Schema,
Name: c.Type.Name,
},
Comment: c.Comment,
NotNull: c.IsNotNull,
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
Length: int32(l),
Comment: c.Comment,
NotNull: c.IsNotNull,
Unsigned: c.IsUnsigned,
IsArray: c.IsArray,
ArrayDims: int32(c.ArrayDims),
Length: int32(l),
Table: &plugin.Identifier{
Catalog: t.Rel.Catalog,
Schema: t.Rel.Schema,
Expand Down Expand Up @@ -252,6 +253,7 @@ func pluginQueryColumn(c *compiler.Column) *plugin.Column {
NotNull: c.NotNull,
Unsigned: c.Unsigned,
IsArray: c.IsArray,
ArrayDims: int32(c.ArrayDims),
Length: int32(l),
IsNamedParam: c.IsNamedParam,
IsFuncCall: c.IsFuncCall,
Expand Down
Loading

0 comments on commit dfb0a62

Please sign in to comment.