Skip to content

Commit afe114f

Browse files
committed
rename proto rpc service and messages
1 parent 39be076 commit afe114f

File tree

21 files changed

+197
-199
lines changed

21 files changed

+197
-199
lines changed

cmd/sqlc-gen-json/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func main() {
1919
}
2020

2121
func run() error {
22-
var req plugin.CodeGenRequest
22+
var req plugin.GenerateRequest
2323
reqBlob, err := io.ReadAll(os.Stdin)
2424
if err != nil {
2525
return err

internal/cmd/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func parse(ctx context.Context, name, dir string, sql config.SQL, combo config.C
381381
return c.Result(), false
382382
}
383383

384-
func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, result *compiler.Result) (string, *plugin.CodeGenResponse, error) {
384+
func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, result *compiler.Result) (string, *plugin.GenerateResponse, error) {
385385
defer trace.StartRegion(ctx, "codegen").End()
386386
req := codeGenRequest(result, combo)
387387
var handler grpc.ClientConnInterface
@@ -454,7 +454,7 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, re
454454
default:
455455
return "", nil, fmt.Errorf("missing language backend")
456456
}
457-
client := plugin.NewCodeGeneratorClient(handler)
457+
client := plugin.NewCodegenServiceClient(handler)
458458
resp, err := client.Generate(ctx, req)
459459
return out, resp, err
460460
}

internal/cmd/shim.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ func pluginQueryParam(p compiler.Parameter) *plugin.Parameter {
223223
}
224224
}
225225

226-
func codeGenRequest(r *compiler.Result, settings config.CombinedSettings) *plugin.CodeGenRequest {
227-
return &plugin.CodeGenRequest{
226+
func codeGenRequest(r *compiler.Result, settings config.CombinedSettings) *plugin.GenerateRequest {
227+
return &plugin.GenerateRequest{
228228
Settings: pluginSettings(r, settings),
229229
Catalog: pluginCatalog(r.Catalog),
230230
Queries: pluginQueries(r),

internal/cmd/vet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
627627
return nil
628628
}
629629

630-
func vetConfig(req *plugin.CodeGenRequest) *vet.Config {
630+
func vetConfig(req *plugin.GenerateRequest) *vet.Config {
631631
return &vet.Config{
632632
Version: req.Settings.Version,
633633
Engine: req.Settings.Engine,

internal/codegen/golang/gen.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (t *tmplCtx) codegenQueryRetval(q Query) (string, error) {
103103
}
104104
}
105105

106-
func Generate(ctx context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenResponse, error) {
106+
func Generate(ctx context.Context, req *plugin.GenerateRequest) (*plugin.GenerateResponse, error) {
107107
options, err := opts.Parse(req)
108108
if err != nil {
109109
return nil, err
@@ -127,7 +127,7 @@ func Generate(ctx context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenR
127127
return generate(req, options, enums, structs, queries)
128128
}
129129

130-
func generate(req *plugin.CodeGenRequest, options *opts.Options, enums []Enum, structs []Struct, queries []Query) (*plugin.CodeGenResponse, error) {
130+
func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum, structs []Struct, queries []Query) (*plugin.GenerateResponse, error) {
131131
i := &importer{
132132
Options: options,
133133
Queries: queries,
@@ -282,7 +282,7 @@ func generate(req *plugin.CodeGenRequest, options *opts.Options, enums []Enum, s
282282
return nil, err
283283
}
284284
}
285-
resp := plugin.CodeGenResponse{}
285+
resp := plugin.GenerateResponse{}
286286

287287
for filename, code := range output {
288288
resp.Files = append(resp.Files, &plugin.File{

internal/codegen/golang/go_type.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/sqlc-dev/sqlc/internal/plugin"
99
)
1010

11-
func addExtraGoStructTags(tags map[string]string, req *plugin.CodeGenRequest, options *opts.Options, col *plugin.Column) {
11+
func addExtraGoStructTags(tags map[string]string, req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) {
1212
for _, override := range options.Overrides {
1313
oride := override.ShimOverride
1414
if oride.GoType.StructTags == nil {
@@ -33,7 +33,7 @@ func addExtraGoStructTags(tags map[string]string, req *plugin.CodeGenRequest, op
3333
}
3434
}
3535

36-
func goType(req *plugin.CodeGenRequest, options *opts.Options, col *plugin.Column) string {
36+
func goType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string {
3737
// Check if the column's type has been overridden
3838
for _, override := range options.Overrides {
3939
oride := override.ShimOverride
@@ -63,7 +63,7 @@ func goType(req *plugin.CodeGenRequest, options *opts.Options, col *plugin.Colum
6363
return typ
6464
}
6565

66-
func goInnerType(req *plugin.CodeGenRequest, options *opts.Options, col *plugin.Column) string {
66+
func goInnerType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string {
6767
columnType := sdk.DataType(col.Type)
6868
notNull := col.NotNull || col.IsArray
6969

internal/codegen/golang/mysql_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/sqlc-dev/sqlc/internal/plugin"
1010
)
1111

12-
func mysqlType(req *plugin.CodeGenRequest, options *opts.Options, col *plugin.Column) string {
12+
func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string {
1313
columnType := sdk.DataType(col.Type)
1414
notNull := col.NotNull || col.IsArray
1515
unsigned := col.Unsigned

internal/codegen/golang/opts/options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type GlobalOptions struct {
4747
Rename map[string]string `json:"rename,omitempty" yaml:"rename"`
4848
}
4949

50-
func Parse(req *plugin.CodeGenRequest) (*Options, error) {
50+
func Parse(req *plugin.GenerateRequest) (*Options, error) {
5151
options, err := parseOpts(req)
5252
if err != nil {
5353
return nil, err
@@ -68,7 +68,7 @@ func Parse(req *plugin.CodeGenRequest) (*Options, error) {
6868
return options, nil
6969
}
7070

71-
func parseOpts(req *plugin.CodeGenRequest) (*Options, error) {
71+
func parseOpts(req *plugin.GenerateRequest) (*Options, error) {
7272
var options Options
7373
if len(req.PluginOptions) == 0 {
7474
return &options, nil
@@ -91,7 +91,7 @@ func parseOpts(req *plugin.CodeGenRequest) (*Options, error) {
9191
return &options, nil
9292
}
9393

94-
func parseGlobalOpts(req *plugin.CodeGenRequest) (*GlobalOptions, error) {
94+
func parseGlobalOpts(req *plugin.GenerateRequest) (*GlobalOptions, error) {
9595
var options GlobalOptions
9696
if len(req.GlobalOptions) == 0 {
9797
return &options, nil

internal/codegen/golang/opts/override.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (o *Override) Matches(n *plugin.Identifier, defaultSchema string) bool {
7676
return true
7777
}
7878

79-
func (o *Override) parse(req *plugin.CodeGenRequest) (err error) {
79+
func (o *Override) parse(req *plugin.GenerateRequest) (err error) {
8080
// validate deprecated postgres_type field
8181
if o.Deprecated_PostgresType != "" {
8282
fmt.Fprintf(os.Stderr, "WARNING: \"postgres_type\" is deprecated. Instead, use \"db_type\" to specify a type override.\n")

internal/codegen/golang/opts/shim.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type ShimOverride struct {
2121
GoType *ShimGoType
2222
}
2323

24-
func shimOverride(req *plugin.CodeGenRequest, o *Override) *ShimOverride {
24+
func shimOverride(req *plugin.GenerateRequest, o *Override) *ShimOverride {
2525
var column string
2626
var table plugin.Identifier
2727

internal/codegen/golang/postgresql_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func parseIdentifierString(name string) (*plugin.Identifier, error) {
3434
}
3535
}
3636

37-
func postgresType(req *plugin.CodeGenRequest, options *opts.Options, col *plugin.Column) string {
37+
func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string {
3838
columnType := sdk.DataType(col.Type)
3939
notNull := col.NotNull || col.IsArray
4040
driver := parseDriver(options.SqlPackage)

internal/codegen/golang/result.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/sqlc-dev/sqlc/internal/plugin"
1313
)
1414

15-
func buildEnums(req *plugin.CodeGenRequest, options *opts.Options) []Enum {
15+
func buildEnums(req *plugin.GenerateRequest, options *opts.Options) []Enum {
1616
var enums []Enum
1717
for _, schema := range req.Catalog.Schemas {
1818
if schema.Name == "pg_catalog" || schema.Name == "information_schema" {
@@ -59,7 +59,7 @@ func buildEnums(req *plugin.CodeGenRequest, options *opts.Options) []Enum {
5959
return enums
6060
}
6161

62-
func buildStructs(req *plugin.CodeGenRequest, options *opts.Options) []Struct {
62+
func buildStructs(req *plugin.GenerateRequest, options *opts.Options) []Struct {
6363
var structs []Struct
6464
for _, schema := range req.Catalog.Schemas {
6565
if schema.Name == "pg_catalog" || schema.Name == "information_schema" {
@@ -182,7 +182,7 @@ func argName(name string) string {
182182
return out
183183
}
184184

185-
func buildQueries(req *plugin.CodeGenRequest, options *opts.Options, structs []Struct) ([]Query, error) {
185+
func buildQueries(req *plugin.GenerateRequest, options *opts.Options, structs []Struct) ([]Query, error) {
186186
qs := make([]Query, 0, len(req.Queries))
187187
for _, query := range req.Queries {
188188
if query.Name == "" {
@@ -332,7 +332,7 @@ func putOutColumns(query *plugin.Query) bool {
332332
// JSON tags: count, count_2, count_2
333333
//
334334
// This is unlikely to happen, so don't fix it yet
335-
func columnsToStruct(req *plugin.CodeGenRequest, options *opts.Options, name string, columns []goColumn, useID bool) (*Struct, error) {
335+
func columnsToStruct(req *plugin.GenerateRequest, options *opts.Options, name string, columns []goColumn, useID bool) (*Struct, error) {
336336
gs := Struct{
337337
Name: name,
338338
}

internal/codegen/golang/sqlite_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/sqlc-dev/sqlc/internal/plugin"
1010
)
1111

12-
func sqliteType(req *plugin.CodeGenRequest, col *plugin.Column) string {
12+
func sqliteType(req *plugin.GenerateRequest, col *plugin.Column) string {
1313
dt := strings.ToLower(sdk.DataType(col.Type))
1414
notNull := col.NotNull || col.IsArray
1515

internal/codegen/json/gen.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/sqlc-dev/sqlc/internal/plugin"
1212
)
1313

14-
func parseOptions(req *plugin.CodeGenRequest) (*opts, error) {
14+
func parseOptions(req *plugin.GenerateRequest) (*opts, error) {
1515
if len(req.PluginOptions) == 0 {
1616
return new(opts), nil
1717
}
@@ -25,7 +25,7 @@ func parseOptions(req *plugin.CodeGenRequest) (*opts, error) {
2525
return options, nil
2626
}
2727

28-
func Generate(ctx context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenResponse, error) {
28+
func Generate(ctx context.Context, req *plugin.GenerateRequest) (*plugin.GenerateResponse, error) {
2929
options, err := parseOptions(req)
3030
if err != nil {
3131
return nil, err
@@ -57,7 +57,7 @@ func Generate(ctx context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenR
5757
if err != nil {
5858
return nil, err
5959
}
60-
return &plugin.CodeGenResponse{
60+
return &plugin.GenerateResponse{
6161
Files: []*plugin.File{
6262
{
6363
Name: filename,

internal/ext/handler.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ import (
1212
)
1313

1414
type Handler interface {
15-
Generate(context.Context, *plugin.CodeGenRequest) (*plugin.CodeGenResponse, error)
15+
Generate(context.Context, *plugin.GenerateRequest) (*plugin.GenerateResponse, error)
1616
Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error
1717
NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)
1818
}
1919

2020
type wrapper struct {
21-
fn func(context.Context, *plugin.CodeGenRequest) (*plugin.CodeGenResponse, error)
21+
fn func(context.Context, *plugin.GenerateRequest) (*plugin.GenerateResponse, error)
2222
}
2323

24-
func (w *wrapper) Generate(ctx context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenResponse, error) {
24+
func (w *wrapper) Generate(ctx context.Context, req *plugin.GenerateRequest) (*plugin.GenerateResponse, error) {
2525
return w.fn(ctx, req)
2626
}
2727

2828
func (w *wrapper) Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error {
29-
req, ok := args.(*plugin.CodeGenRequest)
29+
req, ok := args.(*plugin.GenerateRequest)
3030
if !ok {
31-
return fmt.Errorf("args isn't a CodeGenRequest")
31+
return fmt.Errorf("args isn't a GenerateRequest")
3232
}
33-
resp, ok := reply.(*plugin.CodeGenResponse)
33+
resp, ok := reply.(*plugin.GenerateResponse)
3434
if !ok {
35-
return fmt.Errorf("reply isn't a CodeGenResponse")
35+
return fmt.Errorf("reply isn't a GenerateResponse")
3636
}
3737
res, err := w.Generate(ctx, req)
3838
if err != nil {
@@ -46,6 +46,6 @@ func (w *wrapper) NewStream(ctx context.Context, desc *grpc.StreamDesc, method s
4646
return nil, status.Error(codes.Unimplemented, "")
4747
}
4848

49-
func HandleFunc(fn func(context.Context, *plugin.CodeGenRequest) (*plugin.CodeGenResponse, error)) Handler {
49+
func HandleFunc(fn func(context.Context, *plugin.GenerateRequest) (*plugin.GenerateResponse, error)) Handler {
5050
return &wrapper{fn}
5151
}

internal/ext/process/gen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ type Runner struct {
2222
}
2323

2424
func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error {
25-
req, ok := args.(*plugin.CodeGenRequest)
25+
req, ok := args.(*plugin.GenerateRequest)
2626
if !ok {
27-
return fmt.Errorf("args isn't a CodeGenRequest")
27+
return fmt.Errorf("args isn't a GenerateRequest")
2828
}
2929

3030
stdin, err := proto.Marshal(req)
@@ -60,9 +60,9 @@ func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any,
6060
return fmt.Errorf("process: error running command %s", stderr)
6161
}
6262

63-
resp, ok := reply.(*plugin.CodeGenResponse)
63+
resp, ok := reply.(*plugin.GenerateResponse)
6464
if !ok {
65-
return fmt.Errorf("reply isn't a CodeGenResponse")
65+
return fmt.Errorf("reply isn't a GenerateResponse")
6666
}
6767

6868
if err := proto.Unmarshal(out, resp); err != nil {

internal/ext/wasm/nowasm.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"google.golang.org/grpc"
99
"google.golang.org/grpc/codes"
1010
"google.golang.org/grpc/status"
11-
12-
"github.com/sqlc-dev/sqlc/internal/plugin"
1311
)
1412

1513
func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error {

internal/ext/wasm/wasm.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (r *Runner) loadWASM(ctx context.Context, cache string, expected string) ([
192192
// mysterious (reason unknown) bug with wasm plugins when a large amount of
193193
// tables (like there are in the catalog) are sent.
194194
// @see https://github.com/sqlc-dev/sqlc/pull/1748
195-
func removePGCatalog(req *plugin.CodeGenRequest) {
195+
func removePGCatalog(req *plugin.GenerateRequest) {
196196
if req.Catalog == nil || req.Catalog.Schemas == nil {
197197
return
198198
}
@@ -210,9 +210,9 @@ func removePGCatalog(req *plugin.CodeGenRequest) {
210210
}
211211

212212
func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error {
213-
req, ok := args.(*plugin.CodeGenRequest)
213+
req, ok := args.(*plugin.GenerateRequest)
214214
if !ok {
215-
return status.Error(codes.InvalidArgument, "args isn't a CodeGenRequest")
215+
return status.Error(codes.InvalidArgument, "args isn't a GenerateRequest")
216216
}
217217

218218
// Remove the pg_catalog schema. Its sheer size causes unknown issues with wasm plugins
@@ -293,9 +293,9 @@ func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any,
293293
return fmt.Errorf("read file: %w", err)
294294
}
295295

296-
resp, ok := reply.(*plugin.CodeGenResponse)
296+
resp, ok := reply.(*plugin.GenerateResponse)
297297
if !ok {
298-
return fmt.Errorf("reply isn't a CodeGenResponse")
298+
return fmt.Errorf("reply isn't a GenerateResponse")
299299
}
300300

301301
if err := resp.UnmarshalVT(stdoutBlob); err != nil {

0 commit comments

Comments
 (0)