-
Notifications
You must be signed in to change notification settings - Fork 2
/
dictionary.go
42 lines (37 loc) · 873 Bytes
/
dictionary.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
package olapsql
import (
"github.com/awatercolorpen/olap-sql/api/types"
)
type Option struct {
AdapterOption
}
type Dictionary struct {
Adapter IAdapter
}
func (d *Dictionary) Translator(query *types.Query) (Translator, error) {
set, err := d.Adapter.GetDataSetByKey(query.DataSetName)
if err != nil {
return nil, err
}
option := &TranslatorOption{
Adapter: d.Adapter,
Query: query,
DBType: set.DBType,
Current: set.GetCurrent(),
}
return NewTranslator(option)
}
func (d *Dictionary) Translate(query *types.Query) (types.Clause, error) {
translator, err := d.Translator(query)
if err != nil {
return nil, err
}
return translator.Translate(query)
}
func NewDictionary(option *Option) (*Dictionary, error) {
adapter, err := NewAdapter(&option.AdapterOption)
if err != nil {
return nil, err
}
return &Dictionary{Adapter: adapter}, nil
}