forked from pganalyze/pg_query_go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alter_table_cmd.go
87 lines (72 loc) · 1.92 KB
/
alter_table_cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Auto-generated from postgres/src/include/nodes/parsenodes.h - DO NOT EDIT
package pg_query
import "encoding/json"
/* ----------------------
* Alter Table
* ----------------------
*/
type AlterTableCmd struct {
Subtype AlterTableType `json:"subtype"` /* Type of table alteration to apply */
Name *string `json:"name"` /* column, constraint, or trigger to act on,
* or tablespace */
Newowner *RoleSpec `json:"newowner"`
Def Node `json:"def"` /* definition of new column, index,
* constraint, or parent table */
Behavior DropBehavior `json:"behavior"` /* RESTRICT or CASCADE for DROP cases */
MissingOk bool `json:"missing_ok"` /* skip error if missing? */
}
func (node AlterTableCmd) MarshalJSON() ([]byte, error) {
type AlterTableCmdMarshalAlias AlterTableCmd
return json.Marshal(map[string]interface{}{
"AlterTableCmd": (*AlterTableCmdMarshalAlias)(&node),
})
}
func (node *AlterTableCmd) UnmarshalJSON(input []byte) (err error) {
var fields map[string]json.RawMessage
err = json.Unmarshal(input, &fields)
if err != nil {
return
}
if fields["subtype"] != nil {
err = json.Unmarshal(fields["subtype"], &node.Subtype)
if err != nil {
return
}
}
if fields["name"] != nil {
err = json.Unmarshal(fields["name"], &node.Name)
if err != nil {
return
}
}
if fields["newowner"] != nil {
var nodePtr *Node
nodePtr, err = UnmarshalNodePtrJSON(fields["newowner"])
if err != nil {
return
}
if nodePtr != nil && *nodePtr != nil {
val := (*nodePtr).(RoleSpec)
node.Newowner = &val
}
}
if fields["def"] != nil {
node.Def, err = UnmarshalNodeJSON(fields["def"])
if err != nil {
return
}
}
if fields["behavior"] != nil {
err = json.Unmarshal(fields["behavior"], &node.Behavior)
if err != nil {
return
}
}
if fields["missing_ok"] != nil {
err = json.Unmarshal(fields["missing_ok"], &node.MissingOk)
if err != nil {
return
}
}
return
}