Skip to content

Commit

Permalink
fix dropdata
Browse files Browse the repository at this point in the history
  • Loading branch information
jairad26 committed Nov 12, 2024
1 parent 84c44c7 commit 23b6a15
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 3 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ func (db *DB) DropData(ctx context.Context) error {
}

p := &pb.Proposal{Mutations: &pb.Mutations{
GroupId: 1,
DropOp: pb.Mutations_DATA,
GroupId: 1,
DropOp: pb.Mutations_DATA,
DropValue: strconv.FormatUint(0, 10),
}}
if err := worker.ApplyMutations(ctx, p); err != nil {
return fmt.Errorf("error applying mutation: %w", err)
Expand Down
38 changes: 38 additions & 0 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,44 @@ func TestNonGalaxyNamespace(t *testing.T) {

}

func TestDropData(t *testing.T) {
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
defer db.Close()

require.NoError(t, db.DropAll(context.Background()))
require.NoError(t, db.AlterSchema(context.Background(), "name: string @index(exact) .", 0))

_, err = db.Mutate(context.Background(), []*api.Mutation{
{
Set: []*api.NQuad{
{
Namespace: 0,
Subject: "_:aman",
Predicate: "name",
ObjectValue: &api.Value{Val: &api.Value_StrVal{StrVal: "A"}},
},
},
},
}, 0)
require.NoError(t, err)

query := `{
me(func: has(name)) {
name
}
}`
qresp, err := db.Query(context.Background(), query, 0)
require.NoError(t, err)
require.JSONEq(t, `{"me":[{"name":"A"}]}`, string(qresp.GetJson()))

require.NoError(t, db.DropData(context.Background()))

qresp, err = db.Query(context.Background(), query, 0)
require.NoError(t, err)
require.JSONEq(t, `{"me":[]}`, string(qresp.GetJson()))
}

func TestMultipleNamespaces(t *testing.T) {
db, err := modusdb.New(modusdb.NewDefaultConfig(t.TempDir()))
require.NoError(t, err)
Expand Down

0 comments on commit 23b6a15

Please sign in to comment.