Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package postgresql
|
|
|
|
import (
|
|
"github.com/sqlc-dev/sqlc/internal/core/seed"
|
|
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
|
|
)
|
|
|
|
func NewCatalog() *catalog.Catalog {
|
|
c := catalog.New("public")
|
|
c.Schemas = append(c.Schemas, pgTemp())
|
|
c.Schemas = append(c.Schemas, genPGCatalog())
|
|
c.Schemas = append(c.Schemas, genInformationSchema())
|
|
c.SearchPath = []string{"pg_catalog"}
|
|
c.LoadExtension = loadExtension
|
|
return c
|
|
}
|
|
|
|
// genPGCatalog and genInformationSchema build the schemas sqlc knows
|
|
// PostgreSQL by. Both read the dialect directory, which goldeneye writes,
|
|
// and which the analysis core seeds its catalog from as well.
|
|
func genPGCatalog() *catalog.Schema {
|
|
return systemSchema("pg_catalog", pgCatalogFuncs())
|
|
}
|
|
|
|
func genInformationSchema() *catalog.Schema {
|
|
return systemSchema("information_schema", nil)
|
|
}
|
|
|
|
// systemSchema builds a schema from the relations recorded for it. The tables
|
|
// are read fresh each time, because a catalog is free to change the schemas it
|
|
// was built with.
|
|
func systemSchema(name string, funcs []*catalog.Function) *catalog.Schema {
|
|
tables, err := seed.Relations(dialectFS, "dialect", name)
|
|
if err != nil {
|
|
// The relations are embedded in the binary: a failure here means sqlc
|
|
// was built from a broken tree, which no caller can do anything about.
|
|
panic(err)
|
|
}
|
|
return &catalog.Schema{Name: name, Funcs: funcs, Tables: tables}
|
|
}
|