(constraint *pgquery.Constraint)
| 1116 | } |
| 1117 | |
| 1118 | func (p PostgresParser) parseForeignKey(constraint *pgquery.Constraint) (*parser.ForeignKeyDefinition, error) { |
| 1119 | idxCols := util.TransformSlice(constraint.FkAttrs, func(fkAttr *pgquery.Node) parser.Ident { |
| 1120 | v := fkAttr.Node.(*pgquery.Node_String_).String_.Sval |
| 1121 | return parser.NewIdent(v, false) |
| 1122 | }) |
| 1123 | refCols := util.TransformSlice(constraint.PkAttrs, func(pkAttr *pgquery.Node) parser.Ident { |
| 1124 | v := pkAttr.Node.(*pgquery.Node_String_).String_.Sval |
| 1125 | return parser.NewIdent(v, false) |
| 1126 | }) |
| 1127 | |
| 1128 | refName, err := p.parseTableName(constraint.Pktable) |
| 1129 | if err != nil { |
| 1130 | return nil, err |
| 1131 | } |
| 1132 | return &parser.ForeignKeyDefinition{ |
| 1133 | ConstraintName: parser.NewIdent(constraint.Conname, false), |
| 1134 | IndexColumns: idxCols, |
| 1135 | ReferenceColumns: refCols, |
| 1136 | ReferenceName: refName, |
| 1137 | OnDelete: p.parseFkAction(constraint.FkDelAction), |
| 1138 | OnUpdate: p.parseFkAction(constraint.FkUpdAction), |
| 1139 | ConstraintOptions: &parser.ConstraintOptions{ |
| 1140 | Deferrable: constraint.Deferrable, |
| 1141 | InitiallyDeferred: constraint.Initdeferred, |
| 1142 | }, |
| 1143 | }, nil |
| 1144 | } |
| 1145 | |
| 1146 | func (p PostgresParser) parseFkAction(action string) parser.Ident { |
| 1147 | // https://github.com/pganalyze/pg_query_go/blob/v2.2.0/parser/include/nodes/parsenodes.h#L2145-L2149C23 |
no test coverage detected