-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathmultipart.go
More file actions
55 lines (49 loc) · 1.13 KB
/
multipart.go
File metadata and controls
55 lines (49 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package bundler
import (
"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 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 nil, err
}
for _, file := range files {
refs[file] = struct{}{}
}
}
}
var files []*pb.File
for file, _ := range refs {
contents, err := os.ReadFile(file)
if err != nil {
return nil, err
}
files = append(files, &pb.File{
Name: file,
Contents: contents,
})
}
return files, nil
}
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 nil, err
}
files = append(files, &pb.File{
Name: rel,
Contents: contents,
})
}
return files, nil
}