Skip to content

Commit 8691140

Browse files
committed
try as override options type
1 parent bcbe477 commit 8691140

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

internal/cmd/shim.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"strings"
76

87
gopluginopts "github.com/sqlc-dev/sqlc/internal/codegen/golang/opts"
@@ -39,7 +38,7 @@ func pluginOverride(r *compiler.Result, o config.Override) *plugin.Override {
3938

4039
var options []byte
4140
var err error
42-
if o.Options.IsZero() {
41+
if len(o.Options) == 0 {
4342
// Send go-specific override information to the go codegen plugin
4443
options, err = json.Marshal(gopluginopts.OverrideOptions{
4544
GoType: o.GoType,
@@ -49,12 +48,7 @@ func pluginOverride(r *compiler.Result, o config.Override) *plugin.Override {
4948
panic(err) // TODO don't panic, return err
5049
}
5150
} else {
52-
options, err = convert.YAMLtoJSON(o.Options)
53-
if err != nil {
54-
panic(err)
55-
}
56-
57-
fmt.Printf(">>> %s", string(options))
51+
options = o.Options
5852
}
5953

6054
return &plugin.Override{

internal/config/override.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package config
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"os"
67
"strings"
78

89
gopluginopts "github.com/sqlc-dev/sqlc/internal/codegen/golang/opts"
910
"github.com/sqlc-dev/sqlc/internal/pattern"
10-
"gopkg.in/yaml.v3"
1111
)
1212

1313
type Override struct {
@@ -43,8 +43,8 @@ type Override struct {
4343
TableRel *pattern.Match `json:"-"`
4444

4545
// For passing plugin-specific configuration
46-
Plugin string `json:"plugin,omitempty"`
47-
Options yaml.Node `json:"options,omitempty"`
46+
Plugin string `json:"plugin,omitempty"`
47+
Options json.RawMessage `json:"options,omitempty"`
4848
}
4949

5050
func (o Override) hasGoOptions() bool {
@@ -78,7 +78,7 @@ func (o *Override) Parse() (err error) {
7878
return fmt.Errorf("Override specifying both `column` (%q) and `db_type` (%q) is not valid.", o.Column, o.DBType)
7979
case o.Column == "" && o.DBType == "":
8080
return fmt.Errorf("Override must specify one of either `column` or `db_type`")
81-
case o.hasGoOptions() && !o.Options.IsZero():
81+
case o.hasGoOptions() && len(o.Options) > 0:
8282
return fmt.Errorf("Override can specify go_type/go_struct_tag or options but not both")
8383
}
8484

0 commit comments

Comments
 (0)