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-06-25 19:29:24 +03:00
|
|
|
tblName := tblSel.TblName()
|
2023-04-07 11:00:49 +03:00
|
|
|
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 != "" {
|
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
|
|
|
|
}
|