File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package core
2+
3+ import (
4+ "encoding/json"
5+ "fmt"
6+ "github.com/sqlc-dev/plugin-sdk-go/plugin"
7+ )
8+
9+ type Config struct {
10+ SqlDriver string `json:"sql_driver" yaml:"sql_driver"`
11+ ModelType string `json:"model_type" yaml:"model_type"`
12+
13+ Async bool
14+ }
15+
16+ func ParseConfig (req * plugin.GenerateRequest ) (* Config , error ) {
17+ var config Config
18+ if len (req .PluginOptions ) == 0 {
19+ return & config , nil
20+ }
21+ if err := json .Unmarshal (req .PluginOptions , & config ); err != nil {
22+ return nil , fmt .Errorf ("unmarshalling plugin options: %w" , err )
23+ }
24+ if config .SqlDriver == "" {
25+ config .SqlDriver = SQLDriverAioSQLite
26+ }
27+ val , err := isDriverAsync (config .SqlDriver )
28+ if err != nil {
29+ return nil , fmt .Errorf ("invalid options: %s" , err )
30+ }
31+ config .Async = val
32+ if config .ModelType == "" {
33+ config .ModelType = ModelTypeDataclass
34+ }
35+ if err := isModelTypeValid (config .ModelType ); err != nil {
36+ return nil , fmt .Errorf ("invalid options: %s" , err )
37+ }
38+ return & config , nil
39+ }
You can’t perform that action at this time.
0 commit comments