(conf config.SQL, combo config.CombinedSettings, parserOpts opts.Parser)
| 37 | } |
| 38 | |
| 39 | func NewCompiler(conf config.SQL, combo config.CombinedSettings, parserOpts opts.Parser) (*Compiler, error) { |
| 40 | c := &Compiler{conf: conf, combo: combo} |
| 41 | |
| 42 | if conf.Database != nil && conf.Database.Managed { |
| 43 | client := dbmanager.NewClient(combo.Global.Servers) |
| 44 | c.client = client |
| 45 | } |
| 46 | |
| 47 | // Check for database-only mode (analyzer.database: only) |
| 48 | // This feature requires the analyzerv2 experiment to be enabled |
| 49 | databaseOnlyMode := conf.Analyzer.Database.IsOnly() && parserOpts.Experiment.AnalyzerV2 |
| 50 | |
| 51 | switch conf.Engine { |
| 52 | case config.EngineSQLite: |
| 53 | parser := sqlite.NewParser() |
| 54 | c.parser = parser |
| 55 | c.catalog = sqlite.NewCatalog() |
| 56 | c.selector = newSQLiteSelector() |
| 57 | |
| 58 | if databaseOnlyMode { |
| 59 | // Database-only mode requires a database connection |
| 60 | if conf.Database == nil { |
| 61 | return nil, fmt.Errorf("analyzer.database: only requires database configuration") |
| 62 | } |
| 63 | if conf.Database.URI == "" && !conf.Database.Managed { |
| 64 | return nil, fmt.Errorf("analyzer.database: only requires database.uri or database.managed") |
| 65 | } |
| 66 | c.databaseOnlyMode = true |
| 67 | // Create the SQLite analyzer (implements Analyzer interface) |
| 68 | sqliteAnalyzer := sqliteanalyze.New(*conf.Database) |
| 69 | c.analyzer = analyzer.Cached(sqliteAnalyzer, combo.Global, *conf.Database) |
| 70 | // Create the expander using the analyzer as the column getter |
| 71 | c.expander = expander.New(c.analyzer, parser, parser) |
| 72 | } else if conf.Database != nil { |
| 73 | if conf.Analyzer.Database.IsEnabled() { |
| 74 | c.analyzer = analyzer.Cached( |
| 75 | sqliteanalyze.New(*conf.Database), |
| 76 | combo.Global, |
| 77 | *conf.Database, |
| 78 | ) |
| 79 | } |
| 80 | } |
| 81 | case config.EngineMySQL: |
| 82 | c.parser = dolphin.NewParser() |
| 83 | c.catalog = dolphin.NewCatalog() |
| 84 | c.selector = newDefaultSelector() |
| 85 | case config.EnginePostgreSQL: |
| 86 | parser := postgresql.NewParser() |
| 87 | c.parser = parser |
| 88 | c.catalog = postgresql.NewCatalog() |
| 89 | c.selector = newDefaultSelector() |
| 90 | |
| 91 | if databaseOnlyMode { |
| 92 | // Database-only mode requires a database connection |
| 93 | if conf.Database == nil { |
| 94 | return nil, fmt.Errorf("analyzer.database: only requires database configuration") |
| 95 | } |
| 96 | if conf.Database.URI == "" && !conf.Database.Managed { |
no test coverage detected