forked from pganalyze/pg_query_go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_schema_stmt.go
71 lines (60 loc) · 1.84 KB
/
create_schema_stmt.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
// Auto-generated from postgres/src/include/nodes/parsenodes.h - DO NOT EDIT
package pg_query
import "encoding/json"
/* ----------------------
* Create Schema Statement
*
* NOTE: the schemaElts list contains raw parsetrees for component statements
* of the schema, such as CREATE TABLE, GRANT, etc. These are analyzed and
* executed after the schema itself is created.
* ----------------------
*/
type CreateSchemaStmt struct {
Schemaname *string `json:"schemaname"` /* the name of the schema to create */
Authrole *RoleSpec `json:"authrole"` /* the owner of the created schema */
SchemaElts List `json:"schemaElts"` /* schema components (list of parsenodes) */
IfNotExists bool `json:"if_not_exists"` /* just do nothing if schema already exists? */
}
func (node CreateSchemaStmt) MarshalJSON() ([]byte, error) {
type CreateSchemaStmtMarshalAlias CreateSchemaStmt
return json.Marshal(map[string]interface{}{
"CreateSchemaStmt": (*CreateSchemaStmtMarshalAlias)(&node),
})
}
func (node *CreateSchemaStmt) UnmarshalJSON(input []byte) (err error) {
var fields map[string]json.RawMessage
err = json.Unmarshal(input, &fields)
if err != nil {
return
}
if fields["schemaname"] != nil {
err = json.Unmarshal(fields["schemaname"], &node.Schemaname)
if err != nil {
return
}
}
if fields["authrole"] != nil {
var nodePtr *Node
nodePtr, err = UnmarshalNodePtrJSON(fields["authrole"])
if err != nil {
return
}
if nodePtr != nil && *nodePtr != nil {
val := (*nodePtr).(RoleSpec)
node.Authrole = &val
}
}
if fields["schemaElts"] != nil {
node.SchemaElts.Items, err = UnmarshalNodeArrayJSON(fields["schemaElts"])
if err != nil {
return
}
}
if fields["if_not_exists"] != nil {
err = json.Unmarshal(fields["if_not_exists"], &node.IfNotExists)
if err != nil {
return
}
}
return
}