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

Function RemovePsqlMetaCommands

internal/migrations/migrations.go:46–57  ·  view source on GitHub ↗

RemovePsqlMetaCommands strips psql meta-command lines (e.g. `\restrict KEY`, `\unrestrict KEY`, `\connect foo`) from SQL input. These are emitted by pg_dump but are not valid SQL, so they must be removed before parsing.

(contents string)

Source from the content-addressed store, hash-verified

44// `\unrestrict KEY`, `\connect foo`) from SQL input. These are emitted by
45// pg_dump but are not valid SQL, so they must be removed before parsing.
46func RemovePsqlMetaCommands(contents string) string {
47 s := bufio.NewScanner(strings.NewReader(contents))
48 var lines []string
49 for s.Scan() {
50 line := s.Text()
51 if psqlMetaCommand.MatchString(line) {
52 continue
53 }
54 lines = append(lines, line)
55 }
56 return strings.Join(lines, "\n")
57}
58
59func IsDown(filename string) bool {
60 // Remove golang-migrate rollback files.

Callers 2

parseCatalogMethod · 0.92

Calls 2

ScanMethod · 0.45
JoinMethod · 0.45

Tested by 1