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
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package ast
|
|
|
|
import "github.com/sqlc-dev/sqlc/internal/sql/format"
|
|
|
|
const (
|
|
AT_AddColumn AlterTableType = iota
|
|
AT_AlterColumnType
|
|
AT_DropColumn
|
|
AT_DropNotNull
|
|
AT_SetNotNull
|
|
)
|
|
|
|
type AlterTableType int
|
|
|
|
func (t AlterTableType) String() string {
|
|
switch t {
|
|
case AT_AddColumn:
|
|
return "AddColumn"
|
|
case AT_AlterColumnType:
|
|
return "AlterColumnType"
|
|
case AT_DropColumn:
|
|
return "DropColumn"
|
|
case AT_DropNotNull:
|
|
return "DropNotNull"
|
|
case AT_SetNotNull:
|
|
return "SetNotNull"
|
|
default:
|
|
return "Unknown"
|
|
}
|
|
}
|
|
|
|
type AlterTableCmd struct {
|
|
Tag NodeTag[AlterTableCmd] `json:"tag"`
|
|
|
|
Subtype AlterTableType `json:"subtype"`
|
|
Name *string `json:"name,omitempty"`
|
|
Def *ColumnDef `json:"def,omitempty"`
|
|
Newowner *RoleSpec `json:"newowner,omitempty"`
|
|
Behavior DropBehavior `json:"behavior"`
|
|
MissingOk bool `json:"missing_ok"`
|
|
}
|
|
|
|
func (n *AlterTableCmd) Pos() int {
|
|
return 0
|
|
}
|
|
|
|
func (n *AlterTableCmd) Format(buf *TrackedBuffer, d format.Dialect) {
|
|
if n == nil {
|
|
return
|
|
}
|
|
switch n.Subtype {
|
|
case AT_AddColumn:
|
|
buf.WriteString(" ADD COLUMN ")
|
|
case AT_DropColumn:
|
|
buf.WriteString(" DROP COLUMN ")
|
|
}
|
|
|
|
buf.astFormat(n.Def, d)
|
|
}
|