(constraint *pgquery.Constraint)
| 1066 | } |
| 1067 | |
| 1068 | func (p PostgresParser) parseExclusion(constraint *pgquery.Constraint) (*parser.ExclusionDefinition, error) { |
| 1069 | var exs []parser.ExclusionPair |
| 1070 | for _, ex := range constraint.Exclusions { |
| 1071 | nl := ex.GetList() |
| 1072 | if nl == nil { |
| 1073 | return nil, fmt.Errorf("require node list on exclusion: %#v", ex) |
| 1074 | } |
| 1075 | nItems := nl.GetItems() |
| 1076 | if nItems == nil { |
| 1077 | return nil, fmt.Errorf("require items on node list: %#v", nl) |
| 1078 | } |
| 1079 | excludeElement := nItems[0].GetIndexElem() |
| 1080 | if excludeElement == nil { |
| 1081 | return nil, errors.New("require exclude element") |
| 1082 | } |
| 1083 | var expr parser.Expr |
| 1084 | if n := excludeElement.GetExpr(); n != nil { |
| 1085 | parsedExpr, err := p.parseExpr(n) |
| 1086 | if err != nil { |
| 1087 | return nil, err |
| 1088 | } |
| 1089 | expr = parsedExpr |
| 1090 | } else { |
| 1091 | // If there's no expression, just use the column name as an expression |
| 1092 | expr = &parser.ColName{Name: parser.NewIdent(excludeElement.Name, false)} |
| 1093 | } |
| 1094 | |
| 1095 | opList := nItems[1].GetList() |
| 1096 | opItems := opList.GetItems() |
| 1097 | exs = append(exs, parser.ExclusionPair{ |
| 1098 | Expression: expr, |
| 1099 | Operator: opItems[0].Node.(*pgquery.Node_String_).String_.Sval}, |
| 1100 | ) |
| 1101 | } |
| 1102 | var whereExpr parser.Expr |
| 1103 | if whereClause := constraint.GetWhereClause(); whereClause != nil { |
| 1104 | expr, err := p.parseExpr(whereClause) |
| 1105 | if err != nil { |
| 1106 | return nil, err |
| 1107 | } |
| 1108 | whereExpr = expr |
| 1109 | } |
| 1110 | return &parser.ExclusionDefinition{ |
| 1111 | ConstraintName: parser.NewIdent(constraint.Conname, false), |
| 1112 | IndexType: parser.NewIdent(constraint.GetAccessMethod(), false), |
| 1113 | Exclusions: exs, |
| 1114 | Where: parser.NewWhere(parser.WhereStr, whereExpr), |
| 1115 | }, nil |
| 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 { |
no test coverage detected