| 177 | } |
| 178 | |
| 179 | func buildDelete(nid uuid.UUID, rs []*relationtuple.RelationTuple) (query string, args []any, err error) { |
| 180 | if len(rs) == 0 { |
| 181 | return "", nil, errors.WithStack(ketoapi.ErrMalformedInput) |
| 182 | } |
| 183 | |
| 184 | args = make([]any, 0, 6*len(rs)+1) |
| 185 | ors := make([]string, 0, len(rs)) |
| 186 | for _, rt := range rs { |
| 187 | switch s := rt.Subject.(type) { |
| 188 | case *relationtuple.SubjectID: |
| 189 | ors = append(ors, "(namespace = ? AND object = ? AND relation = ? AND subject_id = ? AND subject_set_namespace IS NULL AND subject_set_object IS NULL AND subject_set_relation IS NULL)") |
| 190 | args = append(args, rt.Namespace, rt.Object, rt.Relation, s.ID) |
| 191 | case *relationtuple.SubjectSet: |
| 192 | ors = append(ors, "(namespace = ? AND object = ? AND relation = ? AND subject_id IS NULL AND subject_set_namespace = ? AND subject_set_object = ? AND subject_set_relation = ?)") |
| 193 | args = append(args, rt.Namespace, rt.Object, rt.Relation, s.Namespace, s.Object, s.Relation) |
| 194 | case nil: |
| 195 | return "", nil, errors.WithStack(ketoapi.ErrNilSubject) |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | query = fmt.Sprintf("DELETE FROM %s WHERE (%s) AND nid = ?", (&RelationTuple{}).TableName(), strings.Join(ors, " OR ")) |
| 200 | args = append(args, nid) |
| 201 | return query, args, nil |
| 202 | } |
| 203 | |
| 204 | func (p *Persister) DeleteRelationTuples(ctx context.Context, rs ...*relationtuple.RelationTuple) (err error) { |
| 205 | if len(rs) == 0 { |