mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-21 07:01:41 +03:00
f07edef14d
* Support for --src.schema in commands "slq", "sql", and "inspect"
26 lines
600 B
Go
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
|
|
}
|