Skip to content

Commit

Permalink
sql/ast: Implement DROP TYPE (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy authored Mar 11, 2020
1 parent 1fa689f commit 9fede32
Show file tree
Hide file tree
Showing 10 changed files with 909 additions and 265 deletions.
10 changes: 6 additions & 4 deletions internal/compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ func enumValueName(value string) string {
// end copypasta

func Run(conf config.SQL, combo config.CombinedSettings) (*Result, error) {
var c *catalog.Catalog
var p Parser

switch conf.Engine {
case config.EngineXLemon:
p = sqlite.NewParser()
c = catalog.New("main")
case config.EngineXDolphin:
p = dolphin.NewParser()
c = catalog.New("public") // TODO: What is the default database for MySQL?
case config.EngineXElephant:
p = postgresql.NewParser()
c = postgresql.NewCatalog()
default:
return nil, fmt.Errorf("unknown engine: %s", conf.Engine)
}
Expand All @@ -77,8 +81,7 @@ func Run(conf config.SQL, combo config.CombinedSettings) (*Result, error) {
return nil, err
}

c, err := catalog.Build(stmts)
if err != nil {
if err := c.Build(stmts); err != nil {
return nil, err
}

Expand All @@ -105,8 +108,7 @@ func Run(conf config.SQL, combo config.CombinedSettings) (*Result, error) {
switch t := typ.(type) {
case *catalog.Enum:
var name string
// TODO: This name should be public, not main
if schema.Name == "main" {
if schema.Name == c.DefaultSchema {
name = t.Name
} else {
name = schema.Name + "_" + t.Name
Expand Down
9 changes: 9 additions & 0 deletions internal/postgresql/catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package postgresql

import "github.com/kyleconroy/sqlc/internal/sql/catalog"

func NewCatalog() *catalog.Catalog {
c := catalog.New("public")
c.Schemas = append(c.Schemas, &catalog.Schema{Name: "pg_temp"})
return c
}
Loading

0 comments on commit 9fede32

Please sign in to comment.