2023-04-07 11:00:49 +03:00
|
|
|
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"
|
2023-04-07 11:00:49 +03:00
|
|
|
func doFromTable(rc *Context, tblSel *ast.TblSelectorNode) (string, error) {
|
2023-11-19 03:05:48 +03:00
|
|
|
tbl := tblSel.Table()
|
|
|
|
if tbl.Table == "" {
|
2023-04-07 11:00:49 +03:00
|
|
|
return "", errz.Errorf("selector has empty table name: {%s}", tblSel.Text())
|
|
|
|
}
|
|
|
|
|
2023-11-19 03:05:48 +03:00
|
|
|
clause := "FROM " + tbl.Render(rc.Dialect.Enquote)
|
2023-06-25 19:29:24 +03:00
|
|
|
alias := tblSel.Alias()
|
|
|
|
if alias != "" {
|
2023-07-03 18:34:19 +03:00
|
|
|
clause += " AS " + rc.Dialect.Enquote(alias)
|
2023-06-25 19:29:24 +03:00
|
|
|
}
|
|
|
|
|
2023-04-07 11:00:49 +03:00
|
|
|
return clause, nil
|
|
|
|
}
|