sq/libsq/ast/render/fromtable.go
Neil O'Toole f07edef14d
Add flag --src.schema (#326)
* Support for --src.schema in commands "slq", "sql", and "inspect"
2023-11-18 17:05:48 -07:00

26 lines
600 B
Go

package render
import (
"github.com/neilotoole/sq/libsq/ast"
"github.com/neilotoole/sq/libsq/core/errz"
)
// 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)
alias := tblSel.Alias()
if alias != "" {
clause += " AS " + rc.Dialect.Enquote(alias)
}
return clause, nil
}