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

Function preserveLegacyCatalogBehavior

internal/tools/sqlc-pg-gen/main.go:185–213  ·  view source on GitHub ↗

preserveLegacyCatalogBehavior maintain previous ordering and filtering that was manually done to the generated file pg_catalog.go. Some of the test depend on this ordering - in particular, function lookups where there might be multiple matching functions (due to type overloads) Until sqlc supports "

(allProcs []Proc)

Source from the content-addressed store, hash-verified

183// Until sqlc supports "smarter" looking up of these functions,
184// preserveLegacyCatalogBehavior ensures there are no accidental test breakages
185func preserveLegacyCatalogBehavior(allProcs []Proc) []Proc {
186 // Preserve the legacy sort order of the end-to-end tests
187 sort.SliceStable(allProcs, func(i, j int) bool {
188 fnA := allProcs[i]
189 fnB := allProcs[j]
190
191 if fnA.Name == "lower" && fnB.Name == "lower" && len(fnA.ArgTypes) == 1 && fnA.ArgTypes[0] == "text" {
192 return true
193 }
194
195 if fnA.Name == "generate_series" && fnB.Name == "generate_series" && len(fnA.ArgTypes) == 2 && fnA.ArgTypes[0] == "numeric" {
196 return true
197 }
198
199 return false
200 })
201
202 procs := make([]Proc, 0, len(allProcs))
203 for _, p := range allProcs {
204 // Skip generating pg_catalog.concat to preserve legacy behavior
205 if p.Name == "concat" {
206 continue
207 }
208
209 procs = append(procs, p)
210 }
211
212 return procs
213}
214
215func databaseURL() string {
216 dburl := os.Getenv("DATABASE_URL")

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected