MCPcopy
hub / github.com/ory/keto / buildDelete

Function buildDelete

internal/persistence/sql/relationtuples.go:179–202  ·  view source on GitHub ↗
(nid uuid.UUID, rs []*relationtuple.RelationTuple)

Source from the content-addressed store, hash-verified

177}
178
179func 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
204func (p *Persister) DeleteRelationTuples(ctx context.Context, rs ...*relationtuple.RelationTuple) (err error) {
205 if len(rs) == 0 {

Callers 2

DeleteRelationTuplesMethod · 0.85
TestBuildDeleteFunction · 0.85

Calls 1

TableNameMethod · 0.45

Tested by 1

TestBuildDeleteFunction · 0.68