sq/libsq/ast/render/fromtable.go

26 lines
600 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) {
tbl := tblSel.Table()
if tbl.Table == "" {
return "", errz.Errorf("selector has empty table name: {%s}", tblSel.Text())
}
clause := "FROM " + tbl.Render(rc.Dialect.Enquote)
2023-06-25 19:29:24 +03:00
alias := tblSel.Alias()
if alias != "" {
clause += " AS " + rc.Dialect.Enquote(alias)
2023-06-25 19:29:24 +03:00
}
return clause, nil
}