MCPcopy
hub / github.com/sqlc-dev/sqlc / Glob

Function Glob

internal/sql/sqlpath/read.go:19–66  ·  view source on GitHub ↗

Return a list of SQL files in the listed paths. Only includes files ending in .sql. Omits hidden files, directories, and down migrations. If a path contains *, ?, [, or ], treat the path as a pattern and expand it filepath.Glob.

(patterns []string)

Source from the content-addressed store, hash-verified

17// If a path contains *, ?, [, or ], treat the path as a pattern and expand it
18// filepath.Glob.
19func Glob(patterns []string) ([]string, error) {
20 var files, paths []string
21 for _, pattern := range patterns {
22 if strings.ContainsAny(pattern, "*?[]") {
23 matches, err := filepath.Glob(pattern)
24 if err != nil {
25 return nil, err
26 }
27 // if len(matches) == 0 {
28 // slog.Warn("zero files matched", "pattern", pattern)
29 // }
30 paths = append(paths, matches...)
31 } else {
32 paths = append(paths, pattern)
33 }
34 }
35 for _, path := range paths {
36 f, err := os.Stat(path)
37 if err != nil {
38 return nil, fmt.Errorf("path error: %w", err)
39 }
40 if f.IsDir() {
41 listing, err := os.ReadDir(path)
42 if err != nil {
43 return nil, err
44 }
45 for _, f := range listing {
46 files = append(files, filepath.Join(path, f.Name()))
47 }
48 } else {
49 files = append(files, filepath.Clean(path))
50 }
51 }
52 var sqlFiles []string
53 for _, file := range files {
54 if !strings.HasSuffix(file, ".sql") {
55 continue
56 }
57 if strings.HasPrefix(filepath.Base(file), ".") {
58 continue
59 }
60 if migrations.IsDown(filepath.Base(file)) {
61 continue
62 }
63 sqlFiles = append(sqlFiles, file)
64 }
65 return sqlFiles, nil
66}

Callers 15

parseCatalogMethod · 0.92
parseQueriesMethod · 0.92
remoteGenerateFunction · 0.92
VerifyFunction · 0.92
fetchDatabaseUriMethod · 0.92
checkSQLMethod · 0.92
CreateDBFunction · 0.92
CreateSQLiteDatabaseFunction · 0.92
CreateMySQLDatabaseFunction · 0.92
CreatePostgreSQLDatabaseFunction · 0.92
MySQLFunction · 0.92
postgreSQLFunction · 0.92

Calls 3

IsDownFunction · 0.92
NameMethod · 0.65
JoinMethod · 0.45