github.com/mithrandie/csvq@v1.18.1/lib/query/alias.go (about)

     1  package query
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/mithrandie/csvq/lib/parser"
     7  )
     8  
     9  type AliasMap map[string]string
    10  
    11  func (m AliasMap) Add(alias parser.Identifier, path string) error {
    12  	uname := strings.ToUpper(alias.Literal)
    13  	if _, ok := m[uname]; ok {
    14  		return NewDuplicateTableNameError(alias)
    15  	}
    16  	m[uname] = strings.ToUpper(path)
    17  	return nil
    18  }
    19  
    20  func (m AliasMap) Get(alias parser.Identifier) (string, error) {
    21  	uname := strings.ToUpper(alias.Literal)
    22  	if fpath, ok := m[uname]; ok {
    23  		return fpath, nil
    24  	}
    25  	return "", NewTableNotLoadedError(alias)
    26  }
    27  
    28  func (m AliasMap) Clear() {
    29  	for k := range m {
    30  		delete(m, k)
    31  	}
    32  }