Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: default schema configuration for postgresql
  • Loading branch information
prog8 committed Dec 19, 2024
commit 3c9e7d64567fa77d046e74e8e75be0c46dc75732
2 changes: 1 addition & 1 deletion internal/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err
c.catalog = dolphin.NewCatalog()
case config.EnginePostgreSQL:
c.parser = postgresql.NewParser()
c.catalog = postgresql.NewCatalog()
c.catalog = postgresql.NewCatalog(combo.Package.DefaultSchema)
if conf.Database != nil {
if conf.Analyzer.Database == nil || *conf.Analyzer.Database {
c.analyzer = analyzer.Cached(
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type SQL struct {
Name string `json:"name" yaml:"name"`
Engine Engine `json:"engine,omitempty" yaml:"engine"`
Schema Paths `json:"schema" yaml:"schema"`
DefaultSchema string `json:"default_schema" yaml:"default_schema"`
Queries Paths `json:"queries" yaml:"queries"`
Database *Database `json:"database" yaml:"database"`
StrictFunctionChecks bool `json:"strict_function_checks" yaml:"strict_function_checks"`
Expand Down
9 changes: 6 additions & 3 deletions internal/engine/postgresql/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ func toPointer(x int) *int {
return &x
}

func NewCatalog() *catalog.Catalog {
c := catalog.New("public")
func NewCatalog(defaultSchema string) *catalog.Catalog {
if defaultSchema == "" {
defaultSchema = "public"
}
c := catalog.New(defaultSchema)
c.Schemas = append(c.Schemas, pgTemp())
c.Schemas = append(c.Schemas, genPGCatalog())
c.Schemas = append(c.Schemas, genInformationSchema())
c.SearchPath = []string{"pg_catalog"}
c.SearchPath = []string{"pg_catalog", defaultSchema}
c.LoadExtension = loadExtension
return c
}
Loading