4
4
"encoding/json"
5
5
"fmt"
6
6
"maps"
7
+ "path/filepath"
7
8
8
9
"github.com/sqlc-dev/plugin-sdk-go/plugin"
9
10
)
@@ -16,7 +17,7 @@ type Options struct {
16
17
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
17
18
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
18
19
EmitEmptySlices bool `json:"emit_empty_slices,omitempty" yaml:"emit_empty_slices"`
19
- EmitExportedQueries bool `json:"emit_exported_queries" yaml:"emit_exported_queries`
20
+ EmitExportedQueries bool `json:"emit_exported_queries" yaml:"emit_exported_queries" `
20
21
EmitResultStructPointers bool `json:"emit_result_struct_pointers" yaml:"emit_result_struct_pointers"`
21
22
EmitParamsStructPointers bool `json:"emit_params_struct_pointers" yaml:"emit_params_struct_pointers"`
22
23
EmitMethodsWithDbArgument bool `json:"emit_methods_with_db_argument,omitempty" yaml:"emit_methods_with_db_argument"`
@@ -77,6 +78,14 @@ func parseOpts(req *plugin.GenerateRequest) (*Options, error) {
77
78
return nil , fmt .Errorf ("unmarshalling plugin options: %w" , err )
78
79
}
79
80
81
+ if options .Package == "" {
82
+ if options .Out != "" {
83
+ options .Package = filepath .Base (options .Out )
84
+ } else {
85
+ return nil , fmt .Errorf ("invalid options: missing package name" )
86
+ }
87
+ }
88
+
80
89
for i := range options .Overrides {
81
90
if err := options .Overrides [i ].parse (req ); err != nil {
82
91
return nil , err
@@ -111,6 +120,9 @@ func ValidateOpts(opts *Options) error {
111
120
if opts .EmitMethodsWithDbArgument && opts .EmitPreparedQueries {
112
121
return fmt .Errorf ("invalid options: emit_methods_with_db_argument and emit_prepared_queries options are mutually exclusive" )
113
122
}
123
+ if * opts .QueryParameterLimit < 0 {
124
+ return fmt .Errorf ("invalid options: query parameter limit must not be negative" )
125
+ }
114
126
115
127
return nil
116
128
}
0 commit comments