-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: batch deletion of relation tuples
- Loading branch information
Showing
2 changed files
with
86 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package sql | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ory/x/uuidx" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ory/keto/internal/relationtuple" | ||
) | ||
|
||
func TestBuildDelete(t *testing.T) { | ||
t.Parallel() | ||
nid := uuidx.NewV4() | ||
|
||
q, args, err := buildDelete(nid, nil) | ||
assert.NoError(t, err) | ||
assert.Empty(t, q) | ||
assert.Empty(t, args) | ||
|
||
obj1, obj2, sub1, obj3 := uuidx.NewV4(), uuidx.NewV4(), uuidx.NewV4(), uuidx.NewV4() | ||
|
||
q, args, err = buildDelete(nid, []*relationtuple.RelationTuple{ | ||
{ | ||
Namespace: "ns1", | ||
Object: obj1, | ||
Relation: "rel1", | ||
Subject: &relationtuple.SubjectID{ | ||
ID: sub1, | ||
}, | ||
}, | ||
{ | ||
Namespace: "ns2", | ||
Object: obj2, | ||
Relation: "rel2", | ||
Subject: &relationtuple.SubjectSet{ | ||
Namespace: "ns3", | ||
Object: obj3, | ||
Relation: "rel3", | ||
}, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
|
||
// parentheses are important here | ||
assert.Equal(t, q, "DELETE FROM keto_relation_tuples WHERE ((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) OR (namespace = ? AND object = ? AND relation = ? AND subject_id IS NULL AND subject_set_namespace = ? AND subject_set_object = ? AND subject_set_relation = ?)) AND nid = ?") | ||
assert.Equal(t, []any{"ns1", obj1, "rel1", sub1, "ns2", obj2, "rel2", "ns3", obj3, "rel3", nid}, args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters