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

Method parseCatalog

internal/compiler/compile.go:29–69  ·  view source on GitHub ↗
(schemas []string)

Source from the content-addressed store, hash-verified

27}
28
29func (c *Compiler) parseCatalog(schemas []string) error {
30 files, err := sqlpath.Glob(schemas)
31 if err != nil {
32 return err
33 }
34 merr := multierr.New()
35 for _, filename := range files {
36 blob, err := os.ReadFile(filename)
37 if err != nil {
38 merr.Add(filename, "", 0, err)
39 continue
40 }
41 contents := migrations.RemoveRollbackStatements(string(blob))
42 contents = migrations.RemovePsqlMetaCommands(contents)
43 c.schema = append(c.schema, contents)
44
45 // In database-only mode, we parse the schema to validate syntax
46 // but don't update the catalog - the database will be the source of truth
47 stmts, err := c.parser.Parse(strings.NewReader(contents))
48 if err != nil {
49 merr.Add(filename, contents, 0, err)
50 continue
51 }
52
53 // Skip catalog updates in database-only mode
54 if c.databaseOnlyMode {
55 continue
56 }
57
58 for i := range stmts {
59 if err := c.catalog.Update(stmts[i], c); err != nil {
60 merr.Add(filename, contents, stmts[i].Pos(), err)
61 continue
62 }
63 }
64 }
65 if len(merr.Errs()) > 0 {
66 return merr
67 }
68 return nil
69}
70
71func (c *Compiler) parseQueries(o opts.Parser) (*Result, error) {
72 ctx := context.Background()

Callers 1

ParseCatalogMethod · 0.95

Calls 9

GlobFunction · 0.92
NewFunction · 0.92
RemoveRollbackStatementsFunction · 0.92
RemovePsqlMetaCommandsFunction · 0.92
ErrsMethod · 0.80
ParseMethod · 0.65
PosMethod · 0.65
AddMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected