-
Notifications
You must be signed in to change notification settings - Fork 881
feat(upload): Point upload command at new endpoint #2772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8c2676b
feat(upload): Point upload command at new endpoint
kyleconroy d10b146
fix(config): Remove unused project field
kyleconroy 9eb6f94
Update docs
kyleconroy a93427d
use latest client
kyleconroy 35bfa05
Update docs/howto/upload.md
kyleconroy 023e9de
Update internal/bundler/multipart.go
kyleconroy 41eabf4
whoops
kyleconroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,55 @@ | ||
package bundler | ||
|
||
import ( | ||
"io" | ||
"mime/multipart" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/sqlc-dev/sqlc/internal/config" | ||
pb "github.com/sqlc-dev/sqlc/internal/quickdb/v1" | ||
"github.com/sqlc-dev/sqlc/internal/sql/sqlpath" | ||
) | ||
|
||
func writeInputs(w *multipart.Writer, file string, conf *config.Config) error { | ||
func readInputs(file string, conf *config.Config) ([]*pb.File, error) { | ||
refs := map[string]struct{}{} | ||
refs[filepath.Base(file)] = struct{}{} | ||
|
||
for _, pkg := range conf.SQL { | ||
for _, paths := range []config.Paths{pkg.Schema, pkg.Queries} { | ||
files, err := sqlpath.Glob(paths) | ||
if err != nil { | ||
return err | ||
return nil, err | ||
} | ||
for _, file := range files { | ||
refs[file] = struct{}{} | ||
} | ||
} | ||
} | ||
|
||
var files []*pb.File | ||
for file, _ := range refs { | ||
if err := addPart(w, file); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
params, err := projectMetadata() | ||
if err != nil { | ||
return err | ||
} | ||
params = append(params, [2]string{"project_id", conf.Project.ID}) | ||
for _, val := range params { | ||
if err = w.WriteField(val[0], val[1]); err != nil { | ||
return err | ||
contents, err := os.ReadFile(file) | ||
if err != nil { | ||
return nil, err | ||
} | ||
files = append(files, &pb.File{ | ||
Name: file, | ||
Contents: contents, | ||
}) | ||
} | ||
return nil | ||
return files, nil | ||
} | ||
|
||
func addPart(w *multipart.Writer, file string) error { | ||
h, err := os.Open(file) | ||
if err != nil { | ||
return err | ||
} | ||
defer h.Close() | ||
part, err := w.CreateFormFile("inputs", file) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = io.Copy(part, h) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func writeOutputs(w *multipart.Writer, dir string, output map[string]string) error { | ||
func readOutputs(dir string, output map[string]string) ([]*pb.File, error) { | ||
var files []*pb.File | ||
for filename, contents := range output { | ||
rel, err := filepath.Rel(dir, filename) | ||
if err != nil { | ||
return err | ||
} | ||
part, err := w.CreateFormFile("outputs", rel) | ||
if err != nil { | ||
return err | ||
} | ||
if _, err := io.WriteString(part, contents); err != nil { | ||
return err | ||
return nil, err | ||
} | ||
files = append(files, &pb.File{ | ||
Name: rel, | ||
Contents: contents, | ||
}) | ||
} | ||
return nil | ||
return files, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.