sq/libsq/ast/render/fromtable.go

26 lines
601 B
Go
Raw Normal View History

package render
import (
"github.com/neilotoole/sq/libsq/ast"
"github.com/neilotoole/sq/libsq/core/errz"
)
2023-06-25 19:29:24 +03:00
// doFromTable renders a table selector to SQL.
//
// .actor --> FROM "actor"
// .actor:a --> FROM "actor" "a"
func doFromTable(rc *Context, tblSel *ast.TblSelectorNode) (string, error) {
2023-06-25 19:29:24 +03:00
tblName := tblSel.TblName()
if tblName == "" {
return "", errz.Errorf("selector has empty table name: {%s}", tblSel.Text())
}
2023-06-25 19:29:24 +03:00
clause := "FROM " + rc.Dialect.Enquote(tblName)
alias := tblSel.Alias()
if alias != "" {
clause += " AS " + rc.Dialect.Enquote(alias)
2023-06-25 19:29:24 +03:00
}
return clause, nil
}