@@ -2,7 +2,6 @@ package config
22
33import (
44 "bytes"
5- "encoding/json"
65 "errors"
76 "fmt"
87 "go/types"
@@ -11,6 +10,8 @@ import (
1110 "strings"
1211
1312 "github.com/kyleconroy/sqlc/internal/pg"
13+
14+ yaml "gopkg.in/yaml.v3"
1415)
1516
1617const errMessageNoVersion = `The configuration file must have a version number.
@@ -29,7 +30,7 @@ The only supported version is "1".
2930const errMessageNoPackages = `No packages are configured`
3031
3132type versionSetting struct {
32- Number string `json:"version"`
33+ Number string `json:"version" yaml:"version" `
3334}
3435
3536type Engine string
@@ -40,57 +41,57 @@ const (
4041)
4142
4243type Config struct {
43- Version string `json:"version"`
44- SQL []SQL `json:"sql"`
45- Gen Gen `json:"overrides,omitempty"`
44+ Version string `json:"version" yaml:"version" `
45+ SQL []SQL `json:"sql" yaml:"sql" `
46+ Gen Gen `json:"overrides,omitempty" yaml:"overrides" `
4647}
4748
4849type Gen struct {
49- Go * GenGo `json:"go,omitempty"`
50+ Go * GenGo `json:"go,omitempty" yaml:"go" `
5051}
5152
5253type GenGo struct {
53- Overrides []Override `json:"overrides,omitempty"`
54- Rename map [string ]string `json:"rename,omitempty"`
54+ Overrides []Override `json:"overrides,omitempty" yaml:"overrides" `
55+ Rename map [string ]string `json:"rename,omitempty" yaml:"rename" `
5556}
5657
5758type SQL struct {
58- Engine Engine `json:"engine,omitempty"`
59- Schema string `json:"schema"`
60- Queries string `json:"queries"`
61- Gen SQLGen `json:"gen"`
59+ Engine Engine `json:"engine,omitempty" yaml:"engine" `
60+ Schema string `json:"schema" yaml:"schema" `
61+ Queries string `json:"queries" yaml:"queries" `
62+ Gen SQLGen `json:"gen" yaml:"gen" `
6263}
6364
6465type SQLGen struct {
65- Go * SQLGo `json:"go,omitempty"`
66+ Go * SQLGo `json:"go,omitempty" yaml:"go" `
6667}
6768
6869type SQLGo struct {
69- EmitInterface bool `json:"emit_interface"`
70- EmitJSONTags bool `json:"emit_json_tags"`
71- EmitPreparedQueries bool `json:"emit_prepared_queries"`
72- Package string `json:"package"`
73- Out string `json:"out"`
74- Overrides []Override `json:"overrides,omitempty"`
75- Rename map [string ]string `json:"rename,omitempty"`
70+ EmitInterface bool `json:"emit_interface" yaml:"emit_interface" `
71+ EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags" `
72+ EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries": `
73+ Package string `json:"package" yaml:"package" `
74+ Out string `json:"out" yaml:"out" `
75+ Overrides []Override `json:"overrides,omitempty" yaml:"overrides" `
76+ Rename map [string ]string `json:"rename,omitempty" yaml:"rename" `
7677}
7778
7879type Override struct {
7980 // name of the golang type to use, e.g. `github.com/segmentio/ksuid.KSUID`
80- GoType string `json:"go_type"`
81+ GoType string `json:"go_type" yaml:"go_type" `
8182
8283 // fully qualified name of the Go type, e.g. `github.com/segmentio/ksuid.KSUID`
83- DBType string `json:"db_type"`
84- Deprecated_PostgresType string `json:"postgres_type"`
84+ DBType string `json:"db_type" yaml:"db_type" `
85+ Deprecated_PostgresType string `json:"postgres_type" yaml:"postgres_type" `
8586
8687 // for global overrides only when two different engines are in use
87- Engine Engine `json:"engine,omitempty"`
88+ Engine Engine `json:"engine,omitempty" yaml:"engine" `
8889
8990 // True if the GoType should override if the maching postgres type is nullable
90- Null bool `json:"null"`
91+ Null bool `json:"null" yaml:"null" `
9192
9293 // fully qualified name of the column, e.g. `accounts.id`
93- Column string `json:"column"`
94+ Column string `json:"column" yaml:"column" `
9495
9596 ColumnName string
9697 Table pg.FQN
@@ -202,8 +203,9 @@ func ParseConfig(rd io.Reader) (Config, error) {
202203 var buf bytes.Buffer
203204 var config Config
204205 var version versionSetting
206+
205207 ver := io .TeeReader (rd , & buf )
206- dec := json .NewDecoder (ver )
208+ dec := yaml .NewDecoder (ver )
207209 if err := dec .Decode (& version ); err != nil {
208210 return config , err
209211 }
0 commit comments