Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package ast
|
|
|
|
import "github.com/sqlc-dev/sqlc/internal/sql/format"
|
|
|
|
type CommonTableExpr struct {
|
|
Tag NodeTag[CommonTableExpr] `json:"tag"`
|
|
|
|
Ctename *string `json:"ctename,omitempty"`
|
|
Aliascolnames *List `json:"aliascolnames,omitempty"`
|
|
Ctequery Node `json:"ctequery,omitempty"`
|
|
Location int `json:"location"`
|
|
Cterecursive bool `json:"cterecursive"`
|
|
Cterefcount int `json:"cterefcount"`
|
|
Ctecolnames *List `json:"ctecolnames,omitempty"`
|
|
Ctecoltypes *List `json:"ctecoltypes,omitempty"`
|
|
Ctecoltypmods *List `json:"ctecoltypmods,omitempty"`
|
|
Ctecolcollations *List `json:"ctecolcollations,omitempty"`
|
|
}
|
|
|
|
func (n *CommonTableExpr) Pos() int {
|
|
return n.Location
|
|
}
|
|
|
|
func (n *CommonTableExpr) Format(buf *TrackedBuffer, d format.Dialect) {
|
|
if n == nil {
|
|
return
|
|
}
|
|
if n.Ctename != nil {
|
|
buf.WriteString(*n.Ctename)
|
|
}
|
|
if items(n.Aliascolnames) {
|
|
buf.WriteString("(")
|
|
buf.join(n.Aliascolnames, d, ", ")
|
|
buf.WriteString(")")
|
|
}
|
|
buf.WriteString(" AS (")
|
|
buf.Group()
|
|
buf.Indent()
|
|
// The body's boundary: a comment at the top of the CTE prints here, and
|
|
// an author who broke the line after the parenthesis keeps the CTE — and
|
|
// therefore the statement around it — broken open.
|
|
buf.boundary(n.Ctequery)
|
|
buf.Softline()
|
|
buf.astFormat(n.Ctequery, d)
|
|
buf.EndIndent()
|
|
buf.Softline()
|
|
buf.EndGroup()
|
|
buf.WriteString(")")
|
|
}
|