forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.go
59 lines (51 loc) · 1.33 KB
/
engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package compiler
import (
"fmt"
"github.com/timstudd/sqlc/internal/config"
"github.com/timstudd/sqlc/internal/engine/dolphin"
"github.com/timstudd/sqlc/internal/engine/postgresql"
"github.com/timstudd/sqlc/internal/engine/sqlite"
"github.com/timstudd/sqlc/internal/opts"
"github.com/timstudd/sqlc/internal/sql/catalog"
)
type Compiler struct {
conf config.SQL
combo config.CombinedSettings
catalog *catalog.Catalog
parser Parser
result *Result
}
func NewCompiler(conf config.SQL, combo config.CombinedSettings) *Compiler {
c := &Compiler{conf: conf, combo: combo}
switch conf.Engine {
case config.EngineXLemon:
c.parser = sqlite.NewParser()
c.catalog = catalog.New("main")
case config.EngineMySQL:
c.parser = dolphin.NewParser()
c.catalog = dolphin.NewCatalog()
case config.EnginePostgreSQL:
c.parser = postgresql.NewParser()
c.catalog = postgresql.NewCatalog()
default:
panic(fmt.Sprintf("unknown engine: %s", conf.Engine))
}
return c
}
func (c *Compiler) Catalog() *catalog.Catalog {
return c.catalog
}
func (c *Compiler) ParseCatalog(schema []string) error {
return c.parseCatalog(schema)
}
func (c *Compiler) ParseQueries(queries []string, o opts.Parser) error {
r, err := c.parseQueries(o)
if err != nil {
return err
}
c.result = r
return nil
}
func (c *Compiler) Result() *Result {
return c.result
}