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
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package ast
|
|
|
|
import "github.com/sqlc-dev/sqlc/internal/sql/format"
|
|
|
|
type CreateFunctionStmt struct {
|
|
Tag NodeTag[CreateFunctionStmt] `json:"tag"`
|
|
|
|
Replace bool `json:"replace"`
|
|
Params *List `json:"params,omitempty"`
|
|
ReturnType *TypeName `json:"return_type,omitempty"`
|
|
Func *FuncName `json:"func,omitempty"`
|
|
// TODO: Understand these two fields
|
|
Options *List `json:"options,omitempty"`
|
|
WithClause *List `json:"with_clause,omitempty"`
|
|
}
|
|
|
|
func (n *CreateFunctionStmt) Pos() int {
|
|
return 0
|
|
}
|
|
|
|
func (n *CreateFunctionStmt) Format(buf *TrackedBuffer, d format.Dialect) {
|
|
if n == nil {
|
|
return
|
|
}
|
|
buf.WriteString("CREATE ")
|
|
if n.Replace {
|
|
buf.WriteString("OR REPLACE ")
|
|
}
|
|
buf.WriteString("FUNCTION ")
|
|
buf.astFormat(n.Func, d)
|
|
buf.WriteString("(")
|
|
if items(n.Params) {
|
|
buf.join(n.Params, d, ", ")
|
|
}
|
|
buf.WriteString(")")
|
|
if n.ReturnType != nil {
|
|
buf.WriteString(" RETURNS ")
|
|
buf.astFormat(n.ReturnType, d)
|
|
}
|
|
// Format options (AS, LANGUAGE, etc.)
|
|
if items(n.Options) {
|
|
for _, opt := range n.Options.Items {
|
|
buf.WriteString(" ")
|
|
buf.astFormat(opt, d)
|
|
}
|
|
}
|
|
}
|