Skip to content

Commit a12f302

Browse files
committed
Also include the generated code in the upload request
1 parent ed28bf2 commit a12f302

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

internal/bundler/multipart.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/kyleconroy/sqlc/internal/sql/sqlpath"
1111
)
1212

13-
func writeContents(w *multipart.Writer, file string, conf *config.Config) error {
13+
func writeInputs(w *multipart.Writer, file string, conf *config.Config) error {
1414
refs := map[string]struct{}{}
1515
refs[filepath.Base(file)] = struct{}{}
1616

@@ -50,7 +50,7 @@ func addPart(w *multipart.Writer, file string) error {
5050
return err
5151
}
5252
defer h.Close()
53-
part, err := w.CreateFormFile("contents", file)
53+
part, err := w.CreateFormFile("inputs", file)
5454
if err != nil {
5555
return err
5656
}
@@ -60,3 +60,20 @@ func addPart(w *multipart.Writer, file string) error {
6060
}
6161
return nil
6262
}
63+
64+
func writeOutputs(w *multipart.Writer, dir string, output map[string]string) error {
65+
for filename, contents := range output {
66+
rel, err := filepath.Rel(dir, filename)
67+
if err != nil {
68+
return err
69+
}
70+
part, err := w.CreateFormFile("outputs", rel)
71+
if err != nil {
72+
return err
73+
}
74+
if _, err := io.WriteString(part, contents); err != nil {
75+
return err
76+
}
77+
}
78+
return nil
79+
}

internal/bundler/upload.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package bundler
22

33
import (
44
"bytes"
5-
"compress/gzip"
65
"context"
76
"fmt"
87
"mime/multipart"
@@ -14,37 +13,44 @@ import (
1413
type Uploader struct {
1514
configPath string
1615
config *config.Config
16+
dir string
1717
}
1818

19-
func NewUploader(configPath string, conf *config.Config) *Uploader {
19+
func NewUploader(configPath, dir string, conf *config.Config) *Uploader {
2020
return &Uploader{
2121
configPath: configPath,
2222
config: conf,
23+
dir: dir,
2324
}
2425
}
2526

26-
func (up *Uploader) Upload(ctx context.Context) error {
27+
func (up *Uploader) Upload(ctx context.Context, result map[string]string) error {
2728
body := bytes.NewBuffer([]byte{})
2829

29-
gw := gzip.NewWriter(body)
30-
defer gw.Close()
31-
w := multipart.NewWriter(gw)
30+
// gw := gzip.NewWriter(body)
31+
// defer gw.Close()
32+
w := multipart.NewWriter(body)
3233
defer w.Close()
3334

34-
if err := writeContents(w, up.configPath, up.config); err != nil {
35+
if err := writeInputs(w, up.configPath, up.config); err != nil {
3536
return err
3637
}
37-
38-
if err := gw.Flush(); err != nil {
38+
if err := writeOutputs(w, up.dir, result); err != nil {
3939
return err
4040
}
41+
42+
// if err := gw.Flush(); err != nil {
43+
// return err
44+
// }
4145
w.Close()
42-
gw.Close()
46+
// gw.Close()
4347

44-
req, err := http.NewRequest("POST", "http://localhost:8000/upload", body)
48+
req, err := http.NewRequest("POST", "http://localhost:8090/upload", body)
4549
if err != nil {
4650
return err
4751
}
52+
53+
// Set sqlc-version header
4854
req.Header.Set("Content-Type", w.FormDataContentType())
4955
req = req.WithContext(ctx)
5056

internal/cmd/package.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ var packageCmd = &cobra.Command{
2626
}
2727

2828
func createPkg(ctx context.Context, e Env, dir, filename string, stderr io.Writer) error {
29+
output, err := Generate(ctx, e, dir, filename, stderr)
30+
if err != nil {
31+
os.Exit(1)
32+
}
2933
configPath, conf, err := readConfig(stderr, dir, filename)
3034
if err != nil {
3135
return err
3236
}
33-
up := bundler.NewUploader(configPath, conf)
37+
up := bundler.NewUploader(configPath, dir, conf)
3438
if err != nil {
3539
return err
3640
}
37-
return up.Upload(ctx)
41+
return up.Upload(ctx, output)
3842
}

0 commit comments

Comments
 (0)