Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Flags:
-f, --file string specify an alternate config file (default: sqlc.yaml)
-h, --help help for sqlc
--no-database disable database connections (default: false)
--no-remote disable remote execution (default: false)

Use "sqlc [command] --help" for more information about a command.
```
8 changes: 0 additions & 8 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func init() {
func Do(args []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) int {
rootCmd := &cobra.Command{Use: "sqlc", SilenceUsage: true}
rootCmd.PersistentFlags().StringP("file", "f", "", "specify an alternate config file (default: sqlc.yaml)")
rootCmd.PersistentFlags().Bool("no-remote", false, "disable remote execution (default: false)")
rootCmd.PersistentFlags().Bool("remote", false, "enable remote execution (default: false)")

rootCmd.AddCommand(checkCmd)
rootCmd.AddCommand(createDBCmd)
Expand Down Expand Up @@ -141,20 +139,14 @@ type Env struct {
DryRun bool
Debug opts.Debug
Experiment opts.Experiment
Remote bool
NoRemote bool
}

func ParseEnv(c *cobra.Command) Env {
dr := c.Flag("dry-run")
r := c.Flag("remote")
nr := c.Flag("no-remote")
return Env{
DryRun: dr != nil && dr.Changed,
Debug: opts.DebugFromEnv(),
Experiment: opts.ExperimentFromEnv(),
Remote: r != nil && r.Value.String() == "true",
NoRemote: nr != nil && nr.Value.String() == "true",
}
}

Expand Down
72 changes: 0 additions & 72 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"sync"

"google.golang.org/grpc"
"google.golang.org/grpc/status"

"github.com/sqlc-dev/sqlc/internal/codegen/golang"
genjson "github.com/sqlc-dev/sqlc/internal/codegen/json"
Expand All @@ -24,12 +23,9 @@ import (
"github.com/sqlc-dev/sqlc/internal/ext"
"github.com/sqlc-dev/sqlc/internal/ext/process"
"github.com/sqlc-dev/sqlc/internal/ext/wasm"
"github.com/sqlc-dev/sqlc/internal/info"
"github.com/sqlc-dev/sqlc/internal/multierr"
"github.com/sqlc-dev/sqlc/internal/opts"
"github.com/sqlc-dev/sqlc/internal/plugin"
"github.com/sqlc-dev/sqlc/internal/remote"
"github.com/sqlc-dev/sqlc/internal/sql/sqlpath"
)

const errMessageNoVersion = `The configuration file must have a version number.
Expand Down Expand Up @@ -151,11 +147,6 @@ func Generate(ctx context.Context, dir, filename string, o *Options) (map[string
return nil, err
}

// Comment on why these two methods exist
if conf.Cloud.Project != "" && e.Remote && !e.NoRemote {
return remoteGenerate(ctx, configPath, conf, dir, stderr)
}

g := &generator{
dir: dir,
output: map[string]string{},
Expand Down Expand Up @@ -230,69 +221,6 @@ func (g *generator) ProcessResult(ctx context.Context, combo config.CombinedSett
return nil
}

func remoteGenerate(ctx context.Context, configPath string, conf *config.Config, dir string, stderr io.Writer) (map[string]string, error) {
rpcClient, err := remote.NewClient(conf.Cloud)
if err != nil {
fmt.Fprintf(stderr, "error creating rpc client: %s\n", err)
return nil, err
}

configBytes, err := os.ReadFile(configPath)
if err != nil {
fmt.Fprintf(stderr, "error reading config file %s: %s\n", configPath, err)
return nil, err
}

rpcReq := remote.GenerateRequest{
Version: info.Version,
Inputs: []*remote.File{{Path: filepath.Base(configPath), Bytes: configBytes}},
}

for _, pkg := range conf.SQL {
for _, paths := range []config.Paths{pkg.Schema, pkg.Queries} {
for i, relFilePath := range paths {
paths[i] = filepath.Join(dir, relFilePath)
}
files, err := sqlpath.Glob(paths)
if err != nil {
fmt.Fprintf(stderr, "error globbing paths: %s\n", err)
return nil, err
}
for _, filePath := range files {
fileBytes, err := os.ReadFile(filePath)
if err != nil {
fmt.Fprintf(stderr, "error reading file %s: %s\n", filePath, err)
return nil, err
}
fileRelPath, _ := filepath.Rel(dir, filePath)
rpcReq.Inputs = append(rpcReq.Inputs, &remote.File{Path: fileRelPath, Bytes: fileBytes})
}
}
}

rpcResp, err := rpcClient.Generate(ctx, &rpcReq)
if err != nil {
rpcStatus, ok := status.FromError(err)
if !ok {
return nil, err
}
fmt.Fprintf(stderr, "rpc error: %s", rpcStatus.Message())
return nil, rpcStatus.Err()
}

if rpcResp.ExitCode != 0 {
fmt.Fprintf(stderr, "%s", rpcResp.Stderr)
return nil, errors.New("remote execution returned with non-zero exit code")
}

output := map[string]string{}
for _, file := range rpcResp.Outputs {
output[filepath.Join(dir, file.Path)] = string(file.Bytes)
}

return output, nil
}

func parse(ctx context.Context, name, dir string, sql config.SQL, combo config.CombinedSettings, parserOpts opts.Parser, stderr io.Writer) (*compiler.Result, bool) {
defer trace.StartRegion(ctx, "parse").End()
c, err := compiler.NewCompiler(sql, combo, parserOpts)
Expand Down
1 change: 0 additions & 1 deletion internal/endtoend/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ func TestReplay(t *testing.T) {
Env: cmd.Env{
Debug: opts.DebugFromString(args.Env["SQLCDEBUG"]),
Experiment: opts.ExperimentFromString(args.Env["SQLCEXPERIMENT"]),
NoRemote: true,
},
Stderr: &stderr,
MutateConfig: testctx.Mutate(t, path),
Expand Down
Loading
Loading