snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
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
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
This commit is contained in:
49
internal/sql/ast/common_table_expr.go
Normal file
49
internal/sql/ast/common_table_expr.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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(")")
|
||||
}
|
||||
Reference in New Issue
Block a user